Documentation ¶
Overview ¶
Package loggers provides loggers implementation for log package
Index ¶
- Constants
- Variables
- func AddToLogContext(ctx context.Context, key string, value interface{}) context.Context
- func FetchCallerInfo(skip int, depth int) (function string, file string, line int)
- type BaseLogger
- type Level
- type LogFields
- type Option
- func WithCallerFieldName(name string) Option
- func WithCallerFileDepth(depth int) Option
- func WithCallerInfo(callerInfo bool) Option
- func WithJSONLogs(json bool) Option
- func WithLevelFieldName(name string) Option
- func WithReplaceStdLogger(replaceStdLogger bool) Option
- func WithTimestampFieldName(name string) Option
- type Options
Constants ¶
const ( // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel = iota // 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 `logs.New()`.
Variables ¶
var AllLevels = []Level{ ErrorLevel, WarnLevel, InfoLevel, DebugLevel, }
AllLevels A constant exposing all logging levels
var ( DefaultOptions = Options{ ReplaceStdLogger: false, JSONLogs: true, Level: InfoLevel, TimestampFieldName: "@timestamp", LevelFieldName: "level", CallerInfo: true, CallerFileDepth: 2, CallerFieldName: "caller", } )
DefaultOptions stores all default options in loggers package These options are used by all loggers
Functions ¶
func AddToLogContext ¶
AddToLogContext adds log fields to context. Any info added here will be added to all logs using this context
func FetchCallerInfo ¶
FetchCallerInfo fetches function name, file name and line number from stack skip is the number of stack frames to ascend, with 0 identifying the caller of FetchCallerInfo. depth is the depth of file to use in caller info
Types ¶
type BaseLogger ¶
type BaseLogger interface { // Log logs a message at the given level. The args are key-value pairs. // The key must be a string, while the value can be of any type. // The message is logged with the given level. // Level is the level of the log message. // Skip is the number of stack frames to skip before getting the file name and line number. // If skip is 0, the file and line of the caller of Log is logged. // ctx is the context of the log message. It is used to pass the context fields to the logger Log(ctx context.Context, level Level, skip int, args ...interface{}) // SetLevel sets the level of the logger SetLevel(level Level) // GetLevel gets the level of the logger GetLevel() Level }
BaseLogger is the interface that needs to be implemented by client loggers
type Level ¶
type Level uint32
Level type
func ParseLevel ¶
ParseLevel takes a string level and returns the log level constant.
type LogFields ¶
LogFields contains all fields that have to be added to logs
func FromContext ¶
FromContext fetchs log fields from provided context
type Option ¶
type Option func(*Options)
Option defines an option for BaseLogger
func WithCallerFieldName ¶
WithCallerFieldName sets the name of callerinfo field
func WithCallerFileDepth ¶
WithCallerFileDepth sets the depth of file to use in caller info
func WithCallerInfo ¶
WithCallerInfo enables/disables adding caller info to logs
func WithLevelFieldName ¶
WithLevelFieldName sets the name of the level field in logs
func WithReplaceStdLogger ¶
WithReplaceStdLogger enables/disables replacing std logger
func WithTimestampFieldName ¶
WithTimestampFieldName sets the name of the time stamp field in logs
type Options ¶
type Options struct { // ReplaceStdLogger replaces std logger with this logger ReplaceStdLogger bool // JSONLogs enables/disables json logs JSONLogs bool // Level is the level of the logger Level Level // TimestampFieldName is the name of the timestamp field in logs TimestampFieldName string // LevelFieldName is the name of the level field in logs LevelFieldName string // CallerInfo enables/disables adding caller info to logs CallerInfo bool // CallerFileDepth is the depth of file to use in caller info CallerFileDepth int // CallerFieldName is the name of callerinfo field CallerFieldName string }
Options contain all common options for BaseLoggers
func GetDefaultOptions ¶
func GetDefaultOptions() Options
GetDefaultOptions fetches loggers default options
Directories ¶
Path | Synopsis |
---|---|
Package gokit provides BaseLogger implementation for go-kit/log
|
Package gokit provides BaseLogger implementation for go-kit/log |
Package logrus provides a BaseLogger implementation for logrus
|
Package logrus provides a BaseLogger implementation for logrus |
Package stdlog provides a BaseLogger implementation for golang "log" package
|
Package stdlog provides a BaseLogger implementation for golang "log" package |
Package zap provides a BaseLogger implementation for uber/zap
|
Package zap provides a BaseLogger implementation for uber/zap |