textlog

package
v3.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func Emitter(w io.Writer, opt ...Option) alog.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

func WithDateFormat(layout string) Option

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 WithPrefix

func WithPrefix(prefix string) Option

WithPrefix adds a set prefix to all lines.

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.

func WithUTC

func WithUTC() Option

WithUTC sets timestamps to UTC.

type Options

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

Options holds option values.

Jump to

Keyboard shortcuts

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