Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableLogger ¶ added in v0.2.0
func DisableLogger(name string)
Example ¶
package main import ( "github.com/iand/logfmtr" ) func main() { // Create the logger with a name logger := logfmtr.NewNamed("europa") // It logs normally logger.Info("the sun is shining") // Disable the logger logfmtr.DisableLogger("europa") logger.Info("the sun not shining now") }
Output:
func EnableLogger ¶ added in v0.2.0
func EnableLogger(name string)
func New ¶
New returns a deferred logger that writes in logfmt using the default options. The logger defers configuring its options until it is instantiated with the first call to Info, Error or Enabled or the first call to those function on any child loggers created via V, WithName or WithValues.
Example ¶
package main import ( "github.com/iand/logfmtr" ) func main() { // Create the logger with deferred options logger := logfmtr.New() // Later on set options that all loggers will be based on opts := logfmtr.DefaultOptions() opts.Humanize = true logfmtr.UseOptions(opts) // Logger is instantiated with the options logger.Info("the sun is shining") }
Output:
func NewNamed ¶ added in v0.2.0
NewNamed returns a deferred logger with the given name that writes in logfmt using the default options.
Example ¶
package main import ( "github.com/iand/logfmtr" ) func main() { // Create the logger with a name logger := logfmtr.NewNamed("europa") logger.Info("the sun is shining") }
Output:
func NewWithOptions ¶
NewWithOptions returns an instantiated logger that writes in logfmt using the supplied options. Panics if no writer is supplied in the options.
Example ¶
package main import ( "github.com/iand/logfmtr" ) func main() { opts := logfmtr.DefaultOptions() opts.Humanize = true logger := logfmtr.NewWithOptions(opts) logger.Info("the sun is shining") }
Output:
func SetVerbosity ¶
SetVerbosity sets the global log level. Only loggers with a V level less than or equal to this value will be enabled.
func UseOptions ¶ added in v0.2.0
func UseOptions(opts Options)
UseOptions sets options that new loggers will use when it they are instantiated.
Types ¶
type Options ¶
type Options struct { // Writer is where logs will be written to Writer io.Writer // Humanize changes the log output to a human friendly format Humanize bool // Colorize adds color to the log output. Only applies if Humanize is also true. Colorize bool // TimestampFormat sets the format for log timestamps. Set to empty to disable timestamping // of log messages. Humanize uses a fixed short timestamp format. TimestampFormat string // NameDelim is the delimiter character used when appending names of loggers. NameDelim string // AddCaller indicates that log messages should include the file and line number of the caller of the logger. AddCaller bool // CallerSkip adds frames to skip when determining the caller of the logger. Useful when the logger is wrapped // by another logger. CallerSkip int }
Options contains fields and flags for customizing logger behaviour
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the default options used by New unless overridden by a call to UseOptions. Override the option field to customise behaviour and then pass to UseOptions or NewWithOptions.