logger

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 22 Imported by: 1

Documentation

Overview

Package logger

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadLogLevelFromEnv added in v1.1.3

func ReadLogLevelFromEnv() (zapcore.Level, error)

func SetCallFrame

func SetCallFrame(entry *logrus.Entry, namespace string, skip int)

SetCallFrame set the caller information for the log entry.

func SetCallerFrameWithFileAndLine

func SetCallerFrameWithFileAndLine(entry *logrus.Entry, namespace, functionName, file string, line int)

SetCallerFrameWithFileAndLine set the caller information for the log entry.

Types

type Format added in v1.6.0

type Format string
const (
	FormatJSON   Format = "json"
	FormatPretty Format = "pretty"
)

func ReadLogFormatFromEnv added in v1.7.0

func ReadLogFormatFromEnv() (Format, error)

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

func (*LogPrettyFormatter) Format added in v1.6.0

func (f *LogPrettyFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format renders a single log entry for log file

the original file log format is defined here: github.com/sirupsen/logrus/text_formatter.TextFormatter{}.Format().

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

func (l *Logger) Debug(msg string, fields ...zapcore.Field)

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.10.0

func (l *Logger) DebugContext(ctx context.Context, msg string, fields ...zapcore.Field)

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

func (l *Logger) Error(msg string, fields ...zapcore.Field)

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.10.0

func (l *Logger) ErrorContext(ctx context.Context, msg string, fields ...zapcore.Field)

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

func (l *Logger) Fatal(msg string, fields ...zapcore.Field)

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.10.0

func (l *Logger) FatalContext(ctx context.Context, msg string, fields ...zapcore.Field)

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

func (l *Logger) Info(msg string, fields ...zapcore.Field)

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.10.0

func (l *Logger) InfoContext(ctx context.Context, msg string, fields ...zapcore.Field)

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

func (l *Logger) Warn(msg string, fields ...zapcore.Field)

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.10.0

func (l *Logger) WarnContext(ctx context.Context, msg string, fields ...zapcore.Field)

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

func (l *Logger) With(fields ...zapcore.Field) *Logger

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

func (l *Logger) WithAndSkip(skip int, fields ...zapcore.Field) *Logger

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.10.0

func WithOpenTelemetryDisabled() NewLoggerCallOption

type ZapField

type ZapField zapcore.Field

func (ZapField) MatchValue

func (f ZapField) MatchValue() any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL