Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Default = alog.New(alog.WithEmitter(Emitter(os.Stderr, WithShortFile(), WithDateFormat(time.RFC3339), WithUTC())))
Default is an alog.Emitter with some default options
Functions ¶
func Emitter ¶
Emitter emits log messages as plain text.
Logs are output to w. The format is determined by l. Every entry generates a single Write call to w, and calls are serialized.
Example ¶
ctx := context.Background() l := alog.New(alog.WithCaller(), alog.WithEmitter(Emitter(os.Stdout, WithShortFile(), WithDateFormat(time.RFC3339))), alog.OverrideTimestamp(func() time.Time { return time.Time{} })) structuredVal := struct { X int }{ X: 1, } ctx = alog.AddTags(ctx, "allthese", "tags") ctx = alog.AddStructuredTags(ctx, alog.STag{Key: "structured", Val: structuredVal}) l.Print(ctx, "test")
Output: 0001-01-01T00:00:00Z emitter_test.go:25: [allthese=tags] [structured={X:1}] test
Types ¶
type Option ¶
type Option func(*Options)
Option sets an option for the emitter.
Options are applied in the order specified.
func WithDateFormat ¶
WithDateFormat sets the string format for timestamps using a layout string like the time package would take.
func WithFile ¶
func WithFile() Option
WithFile collects call information on each log line, like the log package's Llongfile flag.
The alog.WithCaller() option also needs to be used when creating the Logger in order to have the file and line information added to the log entries.
func WithShortFile ¶
func WithShortFile() Option
WithShortFile is like WithFile, but only prints the file name instead of the entire path.
The alog.WithCaller() option also needs to be used when creating the Logger in order to have the file and line information added to the log entries.