Documentation ¶
Overview ¶
Package log defines the Logger interface for a structured leveled log, the Factory interface to create instances of the Logger and the Tracer interface used to trace and log the execution time since last Log.
The package further defines three log levels differentiating between the (normally hidden) Debug, (default) Info and (erroneous) Error.
The log can be used both statically by binding a particular logger factory, as in
std.Use(os.Stderr, log.Info, std.DefaultFmtFun) logger := log.Level(log.Info).Field("key", "value") logger.Log("message")
and dynamically by always going via a factory, as in
factory := std.NewFactory(os.Stderr, log.Info, std.DefaultFmtFun) logger := factory.Level(log.Info).Field("key", "value") logger.Log("message")
Index ¶
Constants ¶
const ( // UnsetLevel should not be output by logger implementation. UnsetLevel = iota - 2 // DebugLevel marks detailed output for design purposes. DebugLevel // InfoLevel is the default log output marker. InfoLevel // ErrorLevel marks an error output. ErrorLevel )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Factory ¶
type Factory interface { //New creates a new logger. New() Logger // Threshold sets the minimum logger level threshold for messages to be output. Threshold(min LoggerLevel) }
Factory defines a utility to create new loggers and set the log level threshold.
type Logger ¶
type Logger interface { // Level creates a new logger instance from the current one setting its log level to the value supplied. Level(lvl LoggerLevel) Logger // Field creates a new logger instance from the current one adding a new field value. Field(k string, v interface{}) Logger // Fields creates a new logger instance from the current one adding a collection of field values. Fields(data map[string]interface{}) Logger // Error creates a new logger instance from the current one adding an error // and setting the level to ErrorLevel. Error(err error) Logger // Log outputs the log structure along with a message if the logger level is above or matching // the threshold set in the factory. Log(msg string) Tracer // Logf outputs the log structure along with a formatted message if the logger level is above or // matching the threshold set in the factory. Logf(format string, v ...interface{}) Tracer }
Logger defines the logger interface.
func Field ¶
Field returns a new logger instance from the factory setting a field value as supplied.
func Fields ¶
Fields returns a new logger instance from the factory setting field values as supplied.
func Level ¶
func Level(lvl LoggerLevel) Logger
Level returns a new logger instance from the factory setting its log level to the value supplied.
type Tracer ¶
type Tracer interface { // Trace computes the time elapsed since the tracer was created. It then logs an entry // with message "traced" and field "duration" amounting to the execution duration in seconds. Trace() float64 }
Tracer defines a utility to trace execution time as returned by the logger Log and Logf methods.
func Log ¶
Log constructs a new logger instance from the factory with no context and logs a message.
Directories ¶
Path | Synopsis |
---|---|
Package apex provides a logger implementation using the github.com/apex/log backends.
|
Package apex provides a logger implementation using the github.com/apex/log backends. |
Package std provides a logger implementation via the Go built-in logger.
|
Package std provides a logger implementation via the Go built-in logger. |