jsonmessage

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// JSONTimeStampKey is used to write the time stamp in json messages
	JSONTimeStampKey = "timestamp"
	// JSONLevelKey is used to write the log message concern level.
	JSONLevelKey = "level"
	// JSONMessageKey is used as the log message key in the JSON structure
	JSONMessageKey = "log_message"
	// JSONTimeStampFunc is a override function to set the timestamp to what the user wants.
	// It must retrun a string which allows many formats to fit in.
	// By default the time stamp is a epoch nano number
	// Can be set by a init function in a higher level package.
	JSONTimeStampFunc JSONTimeStamper
)

Functions

This section is empty.

Types

type JSONMessage

type JSONMessage struct {
	// contains filtered or unexported fields
}

JSONMessage is a structure that will contain the message that you want to send.

func New

func New() *JSONMessage

New returns a empty JSONMessage ready to be populated

func (*JSONMessage) Add

func (j *JSONMessage) Add(key string, value interface{})

Add adds on the key that you want to add your message. This can be anything you want.

func (*JSONMessage) Bytes

func (j *JSONMessage) Bytes() []byte

Bytes returns the []byte representation of your message. If there is a error decoding your message it will still return a []byte but will contain the error message in the form of {"Error": "message"}.

func (*JSONMessage) IsDebug

func (j *JSONMessage) IsDebug() bool

IsDebug will return a bool which will indicate that the message is a debug message.

func (JSONMessage) Message

func (j JSONMessage) Message(m ...interface{})

Message sets the message key with what you pass in. It works like fmt.Sprint.

func (JSONMessage) Messagef

func (j JSONMessage) Messagef(format string, m ...interface{})

Messagef sets the message key with what you pass in but also allows for string formatting. It works like fmt.Sprintf.

func (*JSONMessage) PrettyBytes

func (j *JSONMessage) PrettyBytes() []byte

PrettyBytes returns the []byte representation of your message with some json indentation to make it east to read. If there is a error decoding your message it will still return a []byte but will contain the error message in the form of {\n "Error": "message"\n}.

func (*JSONMessage) PrettyString

func (j *JSONMessage) PrettyString() string

PrettyString returns the string presentation of your message. If there is a error decoding your message it will still return a string but will contain the error message in the form of {\n "Error": "message"\n}.

func (*JSONMessage) SetCrit

func (j *JSONMessage) SetCrit()

SetCrit sets level to CRIT

func (*JSONMessage) SetDebug

func (j *JSONMessage) SetDebug()

SetDebug sets level to DEBUG

func (*JSONMessage) SetInfo

func (j *JSONMessage) SetInfo()

SetInfo sets level to INFO

func (*JSONMessage) SetWarn

func (j *JSONMessage) SetWarn()

SetWarn sets level to WARN

func (*JSONMessage) String

func (j *JSONMessage) String() string

String returns the string presentation of your message. If there is a error decoding your message it will still return a string but will contain the error message in the form of {"Error": "message"}.

type JSONTimeStamper

type JSONTimeStamper interface {
	Stamp() string
}

JSONTimeStamper is used to stamp a JSON message with a time stamp of the users desire

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL