Documentation ¶
Index ¶
- Constants
- Variables
- func Contains(name string) bool
- func Debug(args ...interface{})
- func DebugObj(obj interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func ErrorErr(err error, message ...interface{})
- func ErrorErrf(err error, format string, message ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func FatalErr(err error, message ...interface{})
- func FatalErrf(err error, format string, message ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func List() []string
- func Panic(args ...interface{})
- func PanicErr(err error, message ...interface{})
- func PanicErrf(err error, format string, message ...interface{})
- func Panicf(format string, args ...interface{})
- func SetDefault(logger ILogger)
- func SetDefaultBuilder(ctor LoggerBuilder)
- func SetFormatter(formatter IFormatter)
- func SetLevel(level Level)
- func Warn(args ...interface{})
- func WarnErr(err error, message ...interface{})
- func WarnErrf(err error, format string, message ...interface{})
- func Warnf(format string, args ...interface{})
- type BaseFormatter
- type BaseTerminalFormatter
- type Entry
- type IFormatter
- type ILogger
- type ILoggerAsync
- type Level
- type LevelColorScheme
- type LoggerBuilder
- type TerminalColorScheme
- type TerminalFormatter
- type TerminalTheme
Constants ¶
const ( FieldLevel = "level" FieldTimestamp = "timestamp" FieldMessage = "message" FieldLoggerName = "loggerName" )
const LoggerLogrus = "logrus"
LoggerLogrus indicates the name of the predefined logrus ILogger implementation
const LoggerNil = "nil"
LoggerNil indicates the name of the predefined nil ILogger implementation which does nothing when the log functions are invoked.
const (
TemplateDefault = `` /* 132-byte string literal not displayed */
)
Variables ¶
var ( TerminalThemeDefault = &TerminalTheme{ Template: `{{ LoggerName . }}{{ Level . }}{{ Timestamp " HH:mm:ss " . }} {{ .Message }}`, Schemes: TerminalColorScheme{ "loggerName": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, InfoLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, WarnLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, FatalLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, PanicLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, }, "level": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.Bold, fmtc.DarkGray}, InfoLevel: []fmtc.Color{fmtc.Bold, fmtc.Cyan}, WarnLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.Bold, fmtc.Red}, FatalLevel: []fmtc.Color{fmtc.Bold, fmtc.Red}, PanicLevel: []fmtc.Color{fmtc.Bold, fmtc.Red}, }, "timestamp": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.DarkGray}, InfoLevel: []fmtc.Color{fmtc.Cyan}, WarnLevel: []fmtc.Color{fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.Red}, FatalLevel: []fmtc.Color{fmtc.Red}, PanicLevel: []fmtc.Color{fmtc.Red}, }, }, } TerminalThemeAlternative = &TerminalTheme{ Template: `{{ LoggerName . }}{{ Scheme "level" (string " " .Level " ") . }}{{ Timestamp " HH:mm:ss " . }} {{ .Message }}`, Schemes: TerminalColorScheme{ "loggerName": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, InfoLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, WarnLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, FatalLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, PanicLevel: []fmtc.Color{fmtc.Bold, fmtc.Yellow}, }, "level": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.Bold, fmtc.DarkGray}, InfoLevel: []fmtc.Color{fmtc.Bold, fmtc.White, fmtc.BgBlue}, WarnLevel: []fmtc.Color{fmtc.Black, fmtc.BgYellow}, ErrorLevel: []fmtc.Color{fmtc.Bold, fmtc.White, fmtc.BgRed}, FatalLevel: []fmtc.Color{fmtc.Bold, fmtc.White, fmtc.BgRed}, PanicLevel: []fmtc.Color{fmtc.Bold, fmtc.White, fmtc.BgRed}, }, "timestamp": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.BgBlack, fmtc.DarkGray}, InfoLevel: []fmtc.Color{fmtc.BgBlack, fmtc.Cyan}, WarnLevel: []fmtc.Color{fmtc.BgBlack, fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.BgBlack, fmtc.Red}, FatalLevel: []fmtc.Color{fmtc.BgBlack, fmtc.Red}, PanicLevel: []fmtc.Color{fmtc.BgBlack, fmtc.Red}, }, }, } TerminalThemeCliApp = &TerminalTheme{ Template: `{{ Timestamp " HH:mm:ss " . }} {{ Message . " " }}`, Schemes: TerminalColorScheme{ "timestamp": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.Gray}, InfoLevel: []fmtc.Color{fmtc.Cyan}, WarnLevel: []fmtc.Color{fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.Red}, FatalLevel: []fmtc.Color{fmtc.Red}, PanicLevel: []fmtc.Color{fmtc.Red}, }, "message": LevelColorScheme{ DebugLevel: []fmtc.Color{fmtc.Gray}, InfoLevel: []fmtc.Color{fmtc.White}, WarnLevel: []fmtc.Color{fmtc.Yellow}, ErrorLevel: []fmtc.Color{fmtc.LightRed}, FatalLevel: []fmtc.Color{fmtc.LightRed}, PanicLevel: []fmtc.Color{fmtc.LightRed}, }, }, } )
Functions ¶
func Debug ¶
func Debug(args ...interface{})
Debug logs a message at level Debug on the default logger.
func DebugObj ¶ added in v1.0.3
func DebugObj(obj interface{})
DebugObj logs a debug message of a json representation of the provided object. Does nothing if the object is nil.
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a message at level Debug on the default logger.
func Error ¶
func Error(args ...interface{})
Error logs a message at level Error on the default logger.
func ErrorErr ¶ added in v1.0.3
func ErrorErr(err error, message ...interface{})
ErrorErr logs an error using the provided message and error if the error is not nil. Does nothing if the error is nil
func ErrorErrf ¶ added in v1.0.3
ErrorErrf logs an error with a string format using the provided message and error if the error is not nil. Does nothing if the error is nil
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a message at level Error on the default logger.
func Fatal ¶
func Fatal(args ...interface{})
Fatal logs a message at level Fatal on the default logger.
func FatalErr ¶ added in v1.0.3
func FatalErr(err error, message ...interface{})
FatalErr logs a fatal error using the provided message and error if the error is not nil. Does nothing if the error is nil
func FatalErrf ¶ added in v1.0.3
FatalErrf logs an fatal error with a string format using the provided message and error if the error is not nil. Does nothing if the error is nil
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs a message at level Fatal on the default logger.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a message at level Info on the default logger.
func Panic ¶
func Panic(args ...interface{})
Panic logs a message at level Panic on the default logger.
func PanicErr ¶ added in v1.0.3
func PanicErr(err error, message ...interface{})
PanicErr logs a panic error using the provided message and error if the error is not nil. Does nothing if the error is nil
func PanicErrf ¶ added in v1.0.3
PanicErrf logs an panic error with a string format using the provided message and error if the error is not nil. Does nothing if the error is nil
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf logs a message at level Panic on the default logger.
func SetDefault ¶
func SetDefault(logger ILogger)
SetDefault sets a logger instance as the default logger.
func SetDefaultBuilder ¶
func SetDefaultBuilder(ctor LoggerBuilder)
SetDefaultBuilder assigns the default builder to be used when creating new loggers.
func SetFormatter ¶
func SetFormatter(formatter IFormatter)
SetFormatter sets a custom formatter to display the logs
func WarnErr ¶ added in v1.0.3
func WarnErr(err error, message ...interface{})
WarnErr logs a warning using the provided message and error if the error is not nil. Does nothing if the error is nil
Types ¶
type BaseFormatter ¶
type BaseFormatter struct {
// contains filtered or unexported fields
}
BaseFormatter base structure for formatters
func (*BaseFormatter) SetTemplate ¶
func (f *BaseFormatter) SetTemplate(tmpl string) error
type BaseTerminalFormatter ¶
type BaseTerminalFormatter struct { BaseFormatter // Set to true to bypass checking for a TTY before outputting colors. ForceColors bool // Force disabling colors. DisableColors bool // Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/ EnvironmentOverrideColors bool // contains filtered or unexported fields }
BaseTerminalFormatter base structure to create formatters for a terminal
func (*BaseTerminalFormatter) SetTheme ¶
func (f *BaseTerminalFormatter) SetTheme(scheme *TerminalTheme)
type Entry ¶
type Entry struct { // LoggerName indicates to what logger the log entry belongs to LoggerName string // Contains all the fields set by the user. TODO Data map[string]interface{} // Time at which the log entry was created Timestamp time.Time // Level the log entry was logged at: Debug, Info, Warn, Error, Fatal or Panic Level Level // Message passed to Debug, Info, Warn, Error, Fatal or Panic Message string // contains filtered or unexported fields }
Entry represents a log entry.
func (*Entry) AddMetadata ¶
type IFormatter ¶
The Formatter interface is used to implement a custom Formatter. It takes an `Entry`. It exposes all the fields, including the default ones:
* `entry.Data["msg"]`. The message passed from Info, Warn, Error .. * `entry.Data["time"]`. The timestamp. * `entry.Data["level"]. The level the entry was logged at.
Any additional fields added with `WithField` or `WithFields` are also in `entry.Data`. Format is expected to return an array of bytes which are then logged to `logger.Out`.
type ILogger ¶
type ILogger interface { // Name returns the manager name Name() string // SetLevel sets the logging level SetLevel(level Level) // GetLevel gets the logging level GetLevel() Level // Debug logs a message at level Debug on the logger. Debug(args ...interface{}) // Debugf logs a message at level Debug on the logger. Debugf(format string, args ...interface{}) // Info logs a message at level Info on the logger. Info(args ...interface{}) // Infof logs a message at level Info on the logger. Infof(format string, args ...interface{}) // Warn logs a message at level Warn on the logger. Warn(args ...interface{}) // Warnf logs a message at level Warn on the logger. Warnf(format string, args ...interface{}) // Error logs a message at level Error on the logger. Error(args ...interface{}) // Errorf logs a message at level Error on the logger. Errorf(format string, args ...interface{}) // Fatal logs a message at level Fatal on the logger. Fatal(args ...interface{}) // Fatalf logs a message at level Fatal on the logger. Fatalf(format string, args ...interface{}) // Panic logs a message at level Panic on the logger. Panic(args ...interface{}) // Panicf logs a message at level Panic on the logger. Panicf(format string, args ...interface{}) // SetFormatter sets a custom formatter to display the logs SetFormatter(formatter IFormatter) }
ILogger defines the contract for a logger interface to be used by the mgo and mongo packages. This interface matches most commonly used loggers which should make it simple to assign any logger implementation being used. By default it uses the sirupsen/logrus standard logger implementation.
func Default ¶
func Default() ILogger
GetDefault returns the the instance currently set as the default logger
func Get ¶
Get returns an instance of the requested logger by its name. Returns the Nil Logger implementation if a logger by the given name is not found.
{name} - The name of the logger instance to be retrieved.
func New ¶
New creates a new logger instance using the default builder assigned.
{name} - The name of the logger to create. {writer} - (Optional) The io.Writer the logger instance should use. If not provided, it is set to the default writer by the implementation, typically Stdout or Stderr
type ILoggerAsync ¶ added in v1.0.4
type Level ¶
type Level uint32
Level type
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel )
These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.
func ParseLevel ¶
ParseLevel takes a string level and returns the Logrus log level constant.
type LevelColorScheme ¶
type LevelColorScheme map[Level][]fmtc.Color
LevelColorScheme represents the terminal colors associated to the level parsing for each logging level.
type LoggerBuilder ¶
LoggerBuilder defines a logger constructor. The factory contains multiple logger constructors where new loggers with specified names can be created. Also these loggers can have their own io.Writer.
type TerminalColorScheme ¶
type TerminalColorScheme map[string]LevelColorScheme
TerminalColorScheme defines terminal colors that are tied to a log level and a field.
type TerminalFormatter ¶
type TerminalFormatter struct {
BaseTerminalFormatter
}
TextFormatter formats logs into text
func NewTerminalFormatter ¶
func NewTerminalFormatter() *TerminalFormatter
type TerminalTheme ¶
type TerminalTheme struct { Template string Schemes TerminalColorScheme }
TerminalTheme contains the logging theme configuration for terminal logging