Documentation
¶
Overview ¶
Package logger
Index ¶
- func ReadLogLevelFromEnv() (zapcore.Level, error)
- func SetCallFrame(entry *logrus.Entry, namespace string, skip int)
- func SetCallerFrameWithFileAndLine(entry *logrus.Entry, namespace, functionName, file string, line int)
- type Format
- type LogPrettyFormatter
- type Logger
- func (l *Logger) Debug(msg string, fields ...zapcore.Field)
- func (l *Logger) DebugContext(ctx context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Error(msg string, fields ...zapcore.Field)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Fatal(msg string, fields ...zapcore.Field)
- func (l *Logger) FatalContext(ctx context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Info(msg string, fields ...zapcore.Field)
- func (l *Logger) InfoContext(ctx context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) Warn(msg string, fields ...zapcore.Field)
- func (l *Logger) WarnContext(ctx context.Context, msg string, fields ...zapcore.Field)
- func (l *Logger) With(fields ...zapcore.Field) *Logger
- func (l *Logger) WithAndSkip(skip int, fields ...zapcore.Field) *Logger
- type NewLoggerCallOption
- func WithAppName(appName string) NewLoggerCallOption
- func WithCallFrameSkip(skip int) NewLoggerCallOption
- func WithFormat(format Format) NewLoggerCallOption
- func WithHook(hook logrus.Hook) NewLoggerCallOption
- func WithInitialFields(fields map[string]any) NewLoggerCallOption
- func WithLevel(level zapcore.Level) NewLoggerCallOption
- func WithLogFilePath(logFilePath string) NewLoggerCallOption
- func WithLokiRemoteConfig(config *loki.Config) NewLoggerCallOption
- func WithNamespace(namespace string) NewLoggerCallOption
- func WithOpenTelemetryDisabled() NewLoggerCallOption
- type ZapField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadLogLevelFromEnv ¶ added in v1.1.3
func SetCallFrame ¶
SetCallFrame set the caller information for the log entry.
Types ¶
type LogPrettyFormatter ¶ added in v1.6.0
type LogPrettyFormatter struct { logrus.TextFormatter MinimumCallerDepth int }
LogPrettyFormatter defines the format for log file.
func NewLogPrettyFormatter ¶ added in v1.6.0
func NewLogPrettyFormatter() *LogPrettyFormatter
NewLogFileFormatter return the log format for log file.
eg: 2023-06-01T12:00:00 [info] [controllers/some_controller/code_file.go:99] foo key=value
type Logger ¶
type Logger struct { LogrusLogger *logrus.Entry ZapLogger *zap.Logger // contains filtered or unexported fields }
func NewLogger ¶
func NewLogger(callOpts ...NewLoggerCallOption) (*Logger, error)
NewLogger 按需创建 logger 实例。
func (*Logger) Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) DebugContext ¶ added in v1.9.7
DebugContext logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger. Besides that, it also logs the message to the OpenTelemetry span.
func (*Logger) Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) ErrorContext ¶ added in v1.9.7
ErrorContext logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger. Besides that, it also logs the message to the OpenTelemetry span.
func (*Logger) Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
NOTICE: This method calls os.Exit(1) to exit the program. It also prioritizes the execution of logrus' Fatal method over zap's Fatal method.
func (*Logger) FatalContext ¶ added in v1.9.7
FatalContext logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger. Besides that, it also logs the message to the OpenTelemetry span.
func (*Logger) Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) InfoContext ¶ added in v1.9.7
InfoContext logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger. Besides that, it also logs the message to the OpenTelemetry span.
func (*Logger) Warn ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger. Besides that, it also logs the message to the OpenTelemetry span.
func (*Logger) WarnContext ¶ added in v1.9.7
WarnContext logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger. Besides that, it also logs the message to the OpenTelemetry span.
func (*Logger) With ¶ added in v1.2.0
With creates a new logger instance that inherits the context information from the current logger. Fields added to the new logger instance do not affect the current logger instance.
func (*Logger) WithAndSkip ¶ added in v1.5.0
WithAndSkip creates a new logger instance that inherits the context information from the current logger. Fields added to the new logger instance do not affect the current logger instance. The skip parameter is used to determine the number of stack frames to skip when retrieving the caller information.
type NewLoggerCallOption ¶ added in v1.5.0
type NewLoggerCallOption func(*newLoggerOptions)
func WithAppName ¶ added in v1.5.0
func WithAppName(appName string) NewLoggerCallOption
func WithCallFrameSkip ¶ added in v1.5.0
func WithCallFrameSkip(skip int) NewLoggerCallOption
func WithFormat ¶ added in v1.6.0
func WithFormat(format Format) NewLoggerCallOption
func WithHook ¶ added in v1.5.0
func WithHook(hook logrus.Hook) NewLoggerCallOption
func WithInitialFields ¶ added in v1.5.0
func WithInitialFields(fields map[string]any) NewLoggerCallOption
func WithLevel ¶ added in v1.5.0
func WithLevel(level zapcore.Level) NewLoggerCallOption
func WithLogFilePath ¶ added in v1.5.0
func WithLogFilePath(logFilePath string) NewLoggerCallOption
func WithLokiRemoteConfig ¶ added in v1.8.0
func WithLokiRemoteConfig(config *loki.Config) NewLoggerCallOption
func WithNamespace ¶ added in v1.5.0
func WithNamespace(namespace string) NewLoggerCallOption
func WithOpenTelemetryDisabled ¶ added in v1.9.7
func WithOpenTelemetryDisabled() NewLoggerCallOption