Documentation
¶
Overview ¶
Package log is a generic logging library based on logrus (this may change in the future), that minimize the exposure of src-d projects to logrus or any other logging library, as well defines the standard for configuration and usage of the logging libraries in the organization.
Index ¶
Constants ¶
const ( // DebugLevel stands for debug logging level. DebugLevel = "debug" // InfoLevel stands for info logging level (default). InfoLevel = "info" // WarningLevel stands for warning logging level. WarningLevel = "warning" // ErrorLevel stands for error logging level. ErrorLevel = "error" // TextFormat stands for text logging format. TextFormat = "text" // JSONFormat stands for json logging format. JSONFormat = "json" // FluentdFormat stands for fluentd that can be parsed by Kubernetes and Google Container Engine. FluentdFormat = "fluentd" // DefaultLevel is the level used by LoggerFactory when Level is omitted. DefaultLevel = InfoLevel // DefaultFormat is the format used by LoggerFactory when Format is omitted. DefaultFormat = TextFormat )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Logger ¶
type Logger interface { // New returns a copy of the current logger, adding the given Fields. New(Fields) Logger // With returns a copy of the current logger, adding the given Fields. // Alias of New, must be used when is chained with any message function. With(Fields) Logger // Debugf logs a message at level Debug. Debugf(format string, args ...interface{}) // Infof logs a message at level Info. Infof(format string, args ...interface{}) // Warningf logs a message at level Warning. Warningf(format string, args ...interface{}) // Errorf logs an error with a message at level Error. Errorf(err error, format string, args ...interface{}) }
Logger represents a generic logger, based on logrus.Logger
var DefaultLogger Logger
DefaultLogger logger used by the `log.Infof()`, `log.Debugf()`, `log.Warningf()` and `log.Error()` functions. The DefaultLogger is lazily instantiated if nil once this functions are called.
type LoggerFactory ¶
type LoggerFactory struct { // Level as string, values are "info", "debug", "warning" or "error". Level string // Format as string, values are "text", "json" or "fluentnd", by default "text" is used. // when a terminal is not detected "json" is used instead. Format string // Fields in JSON or fluentd format to be used by configured in the new Logger. Fields string // ForceFormat if true the fact of being in a terminal or not is ignored. ForceFormat bool }
LoggerFactory is a logger factory used to instanciate new Loggers, from string configuration, mainly coming from console flags.
var DefaultFactory *LoggerFactory
DefaultFactory logger used by the `log.New()` function. Pre-configured with the environment variables.
The environment variables are autogenerated from the `LoggerFactory` fields, with a prefix `log`, it means that three different variables are available `LOG_LEVEL`, `LOG_FORMAT`, `LOG_FIELDS`, for more information about the values please read the `LoggerFactory` documentation.
func (*LoggerFactory) ApplyToLogrus ¶
func (f *LoggerFactory) ApplyToLogrus() error
ApplyToLogrus configures the standard logrus Logger with the LoggerFactory values. Useful to propagate the configuration to third-party libraries using logrus.