Documentation ¶
Index ¶
Examples ¶
Constants ¶
const ( // Version is the current Gelf version Version string = "1.1" )
Variables ¶
This section is empty.
Functions ¶
func ContextToJSON ¶
ContextToJSON will marshall the logger context into json
func EntryToJSON ¶
EntryToJSON will marshall the logger Entry into json
Types ¶
type DefaultFormatter ¶
type DefaultFormatter struct {
// contains filtered or unexported fields
}
DefaultFormatter is the default Entry formatter
Example ¶
package main import ( "fmt" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" ) func main() { defaultFormatter := formatter.NewDefaultFormatter(formatter.WithContext(true)) fmt.Println(defaultFormatter.Format( logger.Entry{ Message: "My log message", Level: logger.InfoLevel, Context: logger.NewContext().Add("my_key", "my_value"), }, )) }
Output: <info> My log message {"my_key":"my_value"}
func NewDefaultFormatter ¶
func NewDefaultFormatter(options ...Option) *DefaultFormatter
NewDefaultFormatter will create a new DefaultFormatter
type Gelf ¶
type Gelf struct {
// contains filtered or unexported fields
}
Gelf formatter will transform Entry into Gelf format
func (*Gelf) Format ¶
Format will return Entry as gelf
Example ¶
package main import ( "fmt" "os" "time" "bou.ke/monkey" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" ) func main() { monkey.Patch(time.Now, func() time.Time { return time.Unix(513216000, 0) }) monkey.Patch(os.Hostname, func() (string, error) { return "my_fake_hostname", nil }) defer monkey.UnpatchAll() gelfFormatter := formatter.NewGelf() fmt.Println(gelfFormatter.Format(logger.Entry{Message: "My log message", Level: logger.InfoLevel, Context: logger.NewContext().Add("my key", "my_value")})) }
Output: {"version":"1.1","host":"my_fake_hostname","level":6,"timestamp":513216000.000,"short_message":"My log message","full_message":"<info> My log message [ <my key:my_value> ]","_my_key":"my_value"}
type GelfTCPFormatter ¶
type GelfTCPFormatter struct {
*Gelf
}
GelfTCPFormatter will decorate Gelf formatter in order to add null byte between each entry http://docs.graylog.org/en/3.0/pages/gelf.html#gelf-via-tcp
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON formatter will transform a logger entry into JSON it takes an encode function that allows you to encode the data
the encode function is useful if you do not use the default provided logger implementation
func NewJSON ¶
NewJSON will create a new JSON with given json encoder it allow you tu use your own json encoder
func NewJSONEncoder ¶
func NewJSONEncoder() *JSON
NewJSONEncoder will create a new JSON with default json encoder function
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line formatter will transform log Entry into string
type Option ¶
type Option func(*DefaultFormatter)
Option is the option pattern interface for the DefaultFormatter
func WithConditionalColor ¶ added in v0.5.8
WithConditionalColor function will enable ANSI colored formatting
func WithConditionalContext ¶ added in v0.5.8
WithConditionalContext function will display context printing
func WithContext ¶
WithContext function will display context printing