Documentation
¶
Overview ¶
Package alog provides a simple logger that has minimal structuring passed via context.Context.
Example (Levels) ¶
Output: ERROR [[level error]] test
Index ¶
- Variables
- func AddStructuredTags(ctx context.Context, tags ...STag) context.Context
- func AddTags(ctx context.Context, pairs ...string) context.Context
- func Print(ctx context.Context, v ...interface{})
- func Printf(ctx context.Context, f string, v ...interface{})
- type Emitter
- type EmitterFunc
- type Entry
- type Logger
- type Option
- type STag
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Default = New(WithEmitter(defaultEmitter))
Default is the the Logger the package-level Print functions use.
Functions ¶
func AddStructuredTags ¶ added in v3.7.0
AddStructuredTags adds tag structures to the Context.
func AddTags ¶
AddTags adds paired strings to the set of tags in the Context.
Any unpaired strings are ignored.
Types ¶
type Emitter ¶
Emitter is the interface that wraps the Emit method.
Emit handles a log entry in a customized way.
type EmitterFunc ¶
EmitterFunc is an adapter to allow the use of an ordinary function as an Emitter.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a logging object that extracts tags from a context.Context and emits Entry structs.
A nil *Logger is valid to call methods on.
The default text format will have a newline appended if one is not present in the message.
func New ¶
New returns a configured *Logger, ready to use.
See the Option-returning functions in this package for configuration knobs.
func (*Logger) Output ¶
Output emits the supplied string while capturing the caller information "calldepth" frames back in the call stack. The value 2 is almost always what a caller wants. See also: runtime.Caller
func (*Logger) Print ¶
Print calls l.Output to emit a log entry. Arguments are handled like fmt.Print.
type Option ¶
type Option func(*Logger)
Option sets an option on a Logger.
Options are applied in the order specified, meaning if both To and WithEmitter are supplied in a call to New, the last one wins.
func OverrideTimestamp ¶
OverrideTimestamp sets the function that will be used to get the current time for each log entry.
This is primarily meant to be used for testing custom emitters. For example: OverrideTimestamp(func() time.Time { return time.Time{} })
func WithCaller ¶
func WithCaller() Option
WithCaller configures the logger to include the caller information in each log entry.
Example ¶
Output: alog_test.go:61 test
func WithEmitter ¶
WithEmitter configures the logger to call e.Emit() every time it needs to emit a log line.
Calls are not synchronized.
Example ¶
Output: [[allthese tags]] test