jsonmessage

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: Apache-2.0 Imports: 5 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
	// JSONTimeStampKeyHuman is used when writing a human readable timestamp to the message
	JSONTimeStampKeyHuman = "human_readable_timestamp"
	// HumanTimeStampFormat is the time stamp format used for the default timestamp formating
	HumanTimeStampFormat = "Mon Jan _2 2006 15:04:05 MST"
	// JSONErrorKey is used as the key for adding an error message
	JSONErrorKey = "error"
)

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. The timestamp will have already been written.

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) AddHumanTimestamp added in v0.2.0

func (j *JSONMessage) AddHumanTimestamp()

AddHumanTimestamp is used to convert epoch with nanoseconds to a human timestamp. The result is written to the message using the key save in JSONTimeStampKeyHuman. The key under JSONTimeStampKey MUST be a int64 or the key is simply not written. The key under JSONTimeStampKey MUST be a epoch with nano seconds timestamp eg. time.Now().UnixNano() else you will get a strange looking date.

func (*JSONMessage) Addf added in v0.2.0

func (j *JSONMessage) Addf(key string, format string, values ...interface{})

Addf acts like fmt.Sprintf and stores the result under the supplied key. The stored result will be a string.

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) Error added in v0.2.0

func (j *JSONMessage) Error(err error)

Error is a shortcut function that is equivalent to calling Add(JSONErrorKey, err.Error()).

func (*JSONMessage) Errorf added in v0.2.0

func (j *JSONMessage) Errorf(format string, values ...interface{})

Errorf is a shortcut function that is equivalent to calling Addf(JSONErrorKey, format, values...).

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) RawDump added in v0.3.0

func (j *JSONMessage) RawDump() map[string]interface{}

RawDump return a pointer to a JSONMessages internal data structure. Used in conjunction with JSONPrinter Mutator.

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