Documentation ¶
Overview ¶
Package logger is abstraction over logger implementation
Index ¶
- Constants
- func GetRequestID(ctx context.Context) string
- func GetTenantID(ctx context.Context) string
- func ParseLevel(lvl Level) string
- type ContextKey
- type Fields
- type Level
- type Logger
- type LogrusLogger
- func (l LogrusLogger) Debug(args ...interface{})
- func (l LogrusLogger) Error(args ...interface{})
- func (l LogrusLogger) Fatal(args ...interface{})
- func (l LogrusLogger) GetCorrelationID() string
- func (l LogrusLogger) GetLevel() Level
- func (l LogrusLogger) GetTenantID() string
- func (l LogrusLogger) Info(args ...interface{})
- func (l LogrusLogger) Panic(args ...interface{})
- func (l LogrusLogger) SetArea(area string) Logger
- func (l LogrusLogger) SetCorrelationID(correlationID string) Logger
- func (l LogrusLogger) SetLevel(level Level) error
- func (l LogrusLogger) SetOperation(operation string) Logger
- func (l *LogrusLogger) SetOutput(w io.Writer)
- func (l LogrusLogger) SetTenantID(tenantID string) Logger
- func (l LogrusLogger) Trace(args ...interface{})
- func (l LogrusLogger) TrackFuncTime(start time.Time)
- func (l LogrusLogger) Warn(args ...interface{})
- func (l LogrusLogger) WithContext(ctx context.Context) Logger
- func (l LogrusLogger) WithError(err error) Logger
- func (l LogrusLogger) WithField(key string, value interface{}) Logger
- func (l LogrusLogger) WithFields(fields Fields) Logger
Constants ¶
const ContextKeyRequestID = ContextKey("correlationId")
ContextKeyRequestID is correlationId key for context
const ContextKeyTenantID = ContextKey("tenantId")
ContextKeyTenantID is tenantId key for context
Variables ¶
This section is empty.
Functions ¶
func GetRequestID ¶
GetRequestID will get reqID from a http request and return it as a string
func GetTenantID ¶ added in v1.0.6
GetTenantID will get tenantID from current context and return it as a string
Types ¶
type Level ¶
type Level uint32
Level is logger severity level
const ( // PanicLevel level, highest level of severity PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. FatalLevel // ErrorLevel level. ErrorLevel // WarnLevel level. WarnLevel // InfoLevel level. InfoLevel // DebugLevel level. DebugLevel // TraceLevel level. TraceLevel )
func ParseLogrusLevel ¶
ParseLogrusLevel takes a string level and returns the Logrus log level constant.
type Logger ¶
type Logger interface { // SetLevel logging severity level SetLevel(level Level) error // GetLevel returns current logging level GetLevel() Level // SetArea set area logger context SetArea(area string) Logger // SetOperation set operation logger context SetOperation(operation string) Logger // SetCorrelationID set logger context SetCorrelationID(correlationID string) Logger // GetCorrelationID returns CorrelationID for current logger context GetCorrelationID() string // SetTenantID set tenantID for current logger context SetTenantID(tenantID string) Logger // GetTenantID returns TenantID for current logger context GetTenantID() string // WithField adds a filed to log entry WithField(key string, value interface{}) Logger // WithFields adds a struct of fields to the log entry. WithFields(fields Fields) Logger // WithError Add an error as single field to the log entry. WithError(err error) Logger WithContext(ctx context.Context) Logger Trace(args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) // TrackFuncTime creates log record with func execution time TrackFuncTime(start time.Time) }
Logger is Generic logger interface
func NewNopLogger ¶
func NewNopLogger() Logger
NewNopLogger returns a logger that discards all log messages.
type LogrusLogger ¶
type LogrusLogger struct { Logger // CorrelationID is a unique identifier of the request. CorrelationID string // TenantID is a unique identifier of the tenant. TenantID string // contains filtered or unexported fields }
LogrusLogger logrus.Logger implementation of interface
func NewLogrusLogger ¶
func NewLogrusLogger(l logrus.Level) LogrusLogger
NewLogrusLogger creates new instance of LogrusLogger
func (LogrusLogger) Debug ¶
func (l LogrusLogger) Debug(args ...interface{})
Debug creates logs entry with Debug level
func (LogrusLogger) Error ¶
func (l LogrusLogger) Error(args ...interface{})
Error creates logs entry with Error level
func (LogrusLogger) Fatal ¶
func (l LogrusLogger) Fatal(args ...interface{})
Fatal creates logs entry with Fatal level
func (LogrusLogger) GetCorrelationID ¶ added in v1.0.3
func (l LogrusLogger) GetCorrelationID() string
GetCorrelationID returns CorrelationID for current logger context
func (LogrusLogger) GetLevel ¶
func (l LogrusLogger) GetLevel() Level
GetLevel returns current logging level
func (LogrusLogger) GetTenantID ¶ added in v1.0.6
func (l LogrusLogger) GetTenantID() string
GetTenantID returns TenantID for current logger context
func (LogrusLogger) Info ¶
func (l LogrusLogger) Info(args ...interface{})
Info creates logs entry with Info level
func (LogrusLogger) Panic ¶
func (l LogrusLogger) Panic(args ...interface{})
Panic creates logs entry with Panic level
func (LogrusLogger) SetArea ¶ added in v1.0.6
func (l LogrusLogger) SetArea(area string) Logger
SetArea logger context (Area)
func (LogrusLogger) SetCorrelationID ¶ added in v1.0.3
func (l LogrusLogger) SetCorrelationID(correlationID string) Logger
SetCorrelationID set CorrelationID for logger context
func (LogrusLogger) SetLevel ¶
func (l LogrusLogger) SetLevel(level Level) error
SetLevel sets logger level
func (LogrusLogger) SetOperation ¶ added in v1.0.3
func (l LogrusLogger) SetOperation(operation string) Logger
SetOperation logger context (Operation)
func (*LogrusLogger) SetOutput ¶
func (l *LogrusLogger) SetOutput(w io.Writer)
SetOutput sets the output to desired io.Writer like file, stdout, stderr etc
func (LogrusLogger) SetTenantID ¶ added in v1.0.6
func (l LogrusLogger) SetTenantID(tenantID string) Logger
SetTenantID set TenantID for current logger context
func (LogrusLogger) Trace ¶
func (l LogrusLogger) Trace(args ...interface{})
Trace creates logs entry with Trace level
func (LogrusLogger) TrackFuncTime ¶
func (l LogrusLogger) TrackFuncTime(start time.Time)
TrackFuncTime creates log record with func execution time require debug level or higher usage:
func SomeFunction(list *[]string) { defer TimeTrack(time.Now()) // Do whatever you want. }
func (LogrusLogger) Warn ¶
func (l LogrusLogger) Warn(args ...interface{})
Warn creates logs entry with Warn level
func (LogrusLogger) WithContext ¶
func (l LogrusLogger) WithContext(ctx context.Context) Logger
WithContext adds a context to the Entry.
func (LogrusLogger) WithError ¶
func (l LogrusLogger) WithError(err error) Logger
WithError Add an error as single field to the log entry.
func (LogrusLogger) WithField ¶
func (l LogrusLogger) WithField(key string, value interface{}) Logger
WithField adds a filed to log entry
func (LogrusLogger) WithFields ¶
func (l LogrusLogger) WithFields(fields Fields) Logger
WithFields adds a struct of fields to the log entry.