Documentation ¶
Index ¶
Constants ¶
const ( Level = "level" Message = "message" Service = "service" Time = "time" Stdout = "stdout" Noop = "noop" Test = "test" Console = "console" )
Variables ¶
This section is empty.
Functions ¶
func FetchLogLevel ¶
FetchLogLevel returns a Zerolog level for a given value.
Types ¶
type DefaultLoggerFactory ¶
type DefaultLoggerFactory struct{}
DefaultLoggerFactory is the default LoggerFactory implementation.
func (*DefaultLoggerFactory) Create ¶
func (f *DefaultLoggerFactory) Create(options ...LoggerOption) (*Logger, error)
Create returns a new Logger, and accepts a list of LoggerOption. For example:
var logger, _ = log.NewDefaultLoggerFactory().Create()
is equivalent to:
var logger, _ = log.NewDefaultLoggerFactory().Create( log.WithServiceName("default"), // adds {"service":"default"} to log records log.WithLevel(zerolog.InfoLevel), // logs records with level >= info log.WithOutputWriter(os.Stdout), // sends logs records to stdout )
type LogOutputWriter ¶
type LogOutputWriter int
LogOutputWriter is an enum for the log output writers.
const ( StdoutOutputWriter LogOutputWriter = iota NoopOutputWriter TestOutputWriter ConsoleOutputWriter )
func FetchLogOutputWriter ¶
func FetchLogOutputWriter(l string) LogOutputWriter
FetchLogOutputWriter returns a LogOutputWriter for a given value.
func (LogOutputWriter) String ¶
func (l LogOutputWriter) String() string
String returns a string representation of a LogOutputWriter.
type Logger ¶
Logger provides the possibility to generate logs, and inherits of all Zerolog features.
func CtxLogger ¶
CtxLogger retrieves a Logger from a provided context (or creates and appends a new one if missing).
It automatically adds the traceID and spanID log fields depending on current tracing context.
func FromZerolog ¶
FromZerolog converts as Zerolog logger into a Logger.
type LoggerFactory ¶
type LoggerFactory interface {
Create(options ...LoggerOption) (*Logger, error)
}
LoggerFactory is the interface for Logger factories.
func NewDefaultLoggerFactory ¶
func NewDefaultLoggerFactory() LoggerFactory
NewDefaultLoggerFactory returns a DefaultLoggerFactory, implementing LoggerFactory.
type LoggerOption ¶
type LoggerOption func(o *Options)
LoggerOption are functional options for the LoggerFactory implementations.
func WithLevel ¶
func WithLevel(l zerolog.Level) LoggerOption
WithLevel is used to specify the log level to use.
func WithOutputWriter ¶
func WithOutputWriter(w io.Writer) LoggerOption
WithOutputWriter is used to specify the output writer to use.
func WithServiceName ¶
func WithServiceName(n string) LoggerOption
WithServiceName is used to add automatically a service log field value.
type Options ¶
Options are options for the LoggerFactory implementations.
func DefaultLoggerOptions ¶
func DefaultLoggerOptions() Options
DefaultLoggerOptions are the default options used in the DefaultLoggerFactory.