Documentation
¶
Overview ¶
Example (Nolevel) ¶
keyValue, _ := kv.New(kv.SetTimeFormat(""))
log, _ := New(Writer(keyValue))
large := 12345678
log.Log("metrics or whatnot", "something", large)
Output: metrics or whatnot something=12345678
Example (Structure) ¶
keyValue, _ := kv.New(kv.SetTimeFormat(""))
log, _ := New(Writer(keyValue))
log.Warn("invalid something", "id", 344, "error", "generally broken")
Output: [warn] invalid something id=344 error="generally broken"
Index ¶
- func Debug(msg string, args ...interface{})
- func Error(msg string, args ...interface{})
- func Info(msg string, args ...interface{})
- func IsDebug() bool
- func IsInfo() bool
- func IsWarn() bool
- func SetLevel(lvl message.Level)
- func SetLevelAsString(lvl string)
- func SetWriter(w message.Writer)
- func Warn(msg string, args ...interface{})
- type Logger
- func (l *Logger) Debug(msg string, args ...interface{}) *Logger
- func (l *Logger) Error(msg string, args ...interface{}) *Logger
- func (l *Logger) Field(k string, v interface{}) *Logger
- func (l *Logger) Info(msg string, args ...interface{}) *Logger
- func (l *Logger) IsDebug() bool
- func (l *Logger) IsInfo() bool
- func (l *Logger) IsWarn() bool
- func (l *Logger) Log(msg string, args ...interface{}) *Logger
- func (l *Logger) LogAtLevel(lvl message.Level, msg string, args ...interface{}) *Logger
- func (l *Logger) Named(n string) *Logger
- func (l *Logger) SetLevel(lvl message.Level) *Logger
- func (l *Logger) SetLevelAsString(lvl string) *Logger
- func (l *Logger) Warn(msg string, args ...interface{}) *Logger
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDebug ¶ added in v0.4.0
func IsDebug() bool
IsDebug determines the debug status for a logger instance. Use this to conditionally execute blocks of code depending on the log verbosity.
func IsInfo ¶ added in v0.4.0
func IsInfo() bool
IsInfo determines the info status for a logger instance. Use this to conditionally execute blocks of code depending on the log verbosity.
func IsWarn ¶ added in v0.4.0
func IsWarn() bool
IsWarn determines the info status for a logger instance. Use this to conditionally execute blocks of code depending on the log verbosity.
func SetLevel ¶ added in v0.4.0
SetLevel enables changing the minimum level for a logger instance.
func SetLevelAsString ¶ added in v0.4.0
func SetLevelAsString(lvl string)
SetLevelAsString enables changing the minimum level for a logger instance.
func SetWriter ¶ added in v0.4.0
SetWriter sets the writer for the default logger.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a simple levelled logger.
func Field ¶ added in v0.4.0
Field enables changing the default fields for a logger instance.
Example ¶
jsonWriter, _ := json.New(json.SetTimeFormat(""))
log, _ := New(Name("app.database"), Writer(jsonWriter))
// Create a new Logger with pre-defined values
reqID := "555"
msgLog := log.Field("request", reqID)
msgLog.Error("failed to process message")
Output: {"_level":"error","_message":"failed to process message","_name":"app.database","_time":"","request":"555"}
func Named ¶ added in v0.4.0
Named creates a new instance of a logger with a new name.
Example ¶
keyValue, _ := kv.New(kv.SetTimeFormat(""))
log, _ := New(
Name("database"),
Writer(keyValue),
)
log.Error("connection initialised")
Output: [error] database: connection initialised
func (*Logger) Debug ¶
Debug logs a debug message.
func (*Logger) Error ¶
Error logs an error message.
func (*Logger) Field ¶ added in v0.4.0
Field enables changing the default fields for a logger instance.
func (*Logger) Info ¶
Info logs an information message.
func (*Logger) IsDebug ¶
IsDebug determines the debug status for a logger instance. Use this to conditionally execute blocks of code depending on the log verbosity.
func (*Logger) IsInfo ¶
IsInfo determines the info status for a logger instance. Use this to conditionally execute blocks of code depending on the log verbosity.
func (*Logger) IsWarn ¶
IsWarn determines the info status for a logger instance. Use this to conditionally execute blocks of code depending on the log verbosity.
func (*Logger) Log ¶
Log a message with no level.
func (*Logger) LogAtLevel ¶ added in v0.4.0
LogAtLevel logs a message with a specified level.
func (*Logger) Named ¶
Named creates a new instance of a logger with a new name.
func (*Logger) SetLevel ¶ added in v0.4.0
SetLevel enables changing the minimum level for a logger instance.
func (*Logger) SetLevelAsString ¶ added in v0.4.0
SetLevelAsString enables changing the minimum level for a logger instance.
type Option ¶ added in v0.4.0
An Option configures a logger
func Level ¶
Level configures the minimum level to log.
Example ¶
keyValue, _ := kv.New(kv.SetTimeFormat(""))
log, _ := New(
Name("app"),
Level(message.DEBUG),
Writer(keyValue),
)
log.Error("unable to do anything")
Output: [error] app: unable to do anything
func LevelAsString ¶ added in v0.4.0
LevelAsString configures the minimum level to log.
Source Files
¶
- logger.go
- options.go
- std.go