Documentation
¶
Index ¶
- Constants
- func LogLevelFuncForError(err error, logger Logger) func(ctx context.Context, message any, fields ...Field)
- func StdLoggerWithLevel(adapter Logger, level Level, withFields ...Field) *stdlog.Logger
- func ToContext(ctx context.Context, fields ...Field) context.Context
- type Adapter
- func (l *Adapter) Debug(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Error(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Fatal(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Info(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) IsLevelEnabled(level Level) bool
- func (l *Adapter) Level() Level
- func (l *Adapter) Log(ctx context.Context, level Level, msg any, fields ...Field)
- func (l *Adapter) Panic(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Print(ctx context.Context, msg any, fields ...Field)
- func (logger *Adapter) SetFormatter(formatter Formatter)
- func (logger *Adapter) SetOutput(output io.Writer)
- func (logger *Adapter) SetReportCaller(reportCaller bool)
- func (l *Adapter) Trace(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Warn(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Warning(ctx context.Context, msg any, fields ...Field)
- type Config
- type Entry
- type Field
- type FieldMap
- type Fields
- type Formatter
- type FormatterConfig
- type JSONFormatter
- type JSONFormatterConfig
- type Level
- type LogLevelSpecifier
- type Logger
- type LoggerWriter
- type MutexWrap
- type OutputConfig
Constants ¶
View Source
const ( FieldKeyMsg = "msg" FieldKeyLevel = "level" FieldKeyTime = "time" FieldKeyLogError = "log_error" FieldKeyFunc = "func" FieldKeyFile = "file" )
Default key names for the default fields
View Source
const FormatterTypeJson = "json"
Variables ¶
This section is empty.
Functions ¶
func LogLevelFuncForError ¶
func StdLoggerWithLevel ¶
Types ¶
type Adapter ¶
type Adapter struct { Out io.Writer Formatter Formatter ReportCaller bool ExitFunc exitFunc // contains filtered or unexported fields }
func DefaultLoggerWithLevel ¶
func NewFromConfig ¶
func (*Adapter) IsLevelEnabled ¶
IsLevelEnabled checks if the log level of the logger is greater than the level param
func (*Adapter) Log ¶
Log will log a message at the level given as parameter. Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit. For this behaviour logger.Panic or logger.Fatal should be used instead.
func (*Adapter) SetFormatter ¶
SetFormatter sets the logger formatter.
func (*Adapter) SetReportCaller ¶
type Config ¶
type Config struct { Loglevel Level Formatter FormatterConfig Output OutputConfig }
type Entry ¶
type FieldMap ¶
type FieldMap map[fieldKey]string
FieldMap allows customization of the key names for default fields.
type Fields ¶
func ContextLogValues ¶
type FormatterConfig ¶
type FormatterConfig struct { Type string Json *JSONFormatterConfig }
type JSONFormatter ¶
type JSONFormatter struct { TimestampFormat string DisableTimestamp bool DisableHTMLEscape bool DataKey string FieldMap FieldMap CallerPrettifier func(*runtime.Frame) (function string, file string) PrettyPrint bool }
JSONFormatter formats logs into parsable json
type JSONFormatterConfig ¶
type Level ¶
type Level uint32
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 `logger.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 // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
These are the different logging levels. You can set the logging level to log on your instance of logger
func LogLevelForError ¶
func ParseLogLevel ¶
type LogLevelSpecifier ¶
type LogLevelSpecifier interface {
LogLevel() Level
}
type Logger ¶
type Logger interface { Log(ctx context.Context, level Level, msg any, fields ...Field) Trace(ctx context.Context, msg any, fields ...Field) Debug(ctx context.Context, msg any, fields ...Field) Info(ctx context.Context, msg any, fields ...Field) Warn(ctx context.Context, msg any, fields ...Field) Warning(ctx context.Context, msg any, fields ...Field) Error(ctx context.Context, msg any, fields ...Field) Fatal(ctx context.Context, msg any, fields ...Field) Panic(ctx context.Context, msg any, fields ...Field) }
type LoggerWriter ¶
type LoggerWriter struct {
// contains filtered or unexported fields
}
type OutputConfig ¶
Click to show internal directories.
Click to hide internal directories.