Documentation ¶
Index ¶
- Variables
- func AllFormatters() map[string]Formatter
- func AllLevels() map[string]Level
- func GetViper() (*viper.Viper, error)
- func InitLogger(config Config) error
- type Config
- type Formatter
- type Level
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) GenTraceID()
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) SetName(newName string)
- func (l *Logger) SetTraceID(traceID uuid.UUID)
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // StringFormatter instance StringFormatter = newFormatter("string", "%s [%s] %s [%s]: %v") // JSONFormatter instance JSONFormatter = newFormatter("json", "{\"time\":\"%s\",\"level\":\"%s\",\"trace_id\":\"%s\",\"logger\":\"%s\",\"msg\":\"%v\"}") )
View Source
var ( // Panic level Panic = newLevel(panicID, "panic") // Fatal level Fatal = newLevel(fatalID, "fatal") // Error level Error = newLevel(errorID, "error") // Warn level Warn = newLevel(warnID, "warn") // Info level Info = newLevel(infoID, "info") // Debug level Debug = newLevel(debugID, "debug") // Trace level Trace = newLevel(traceID, "trace") )
View Source
var LogFormatter = StringFormatter
LogFormatter Global formatter for the application
View Source
var LogLevel = Error
LogLevel Global level for the application
Functions ¶
func InitLogger ¶
InitLogger initialise the global logger from configuration
Types ¶
type Config ¶
Config configuration fields
func (*Config) LoadValues ¶
LoadValues from viper instance
type Logger ¶
Logger usage
Initialise configuration
loggerConfig := new(logger.Config) err := loggerConfig.InitConfig()
Global initialisation with configuration
logger.InitLogger(loggerConfig)
Create logger in place:
mainLogger := logger.NewNamedLogger("main logger") mainLogger.GenTraceID()
To log a message with Fatal severity:
mainLogger.Fatal("Fatal entry")
Output depend on assigned formatter.
For string formatter it look like this:
2020-04-04T17:22:17+03:00 [fatal] e30375a6-4dc4-40be-8c5f-8656996298ce [main logger]: [[[Fatal entry]]]
For JSON formatter:
{"time":"2020-04-04T17:15:12+03:00","level":"fatal","corelation_id":"ace08634-1245-4557-9754-d015f8d0235a","logger":"main logger","msg":"[[[Fatal entry]]]"}
func NewAnnonymousLogger ¶
func NewAnnonymousLogger() Logger
NewAnnonymousLogger creates new logger without name
func NewNamedLogger ¶
NewNamedLogger creates new named logger
func (*Logger) GenTraceID ¶
func (l *Logger) GenTraceID()
GenTraceID is used to generate and set new Correlation ID
func (*Logger) SetTraceID ¶
SetTraceID is used to set Correlation ID
Click to show internal directories.
Click to hide internal directories.