log

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CustomFieldsKey = "ctx_extra_data"
View Source
const TraceIDKey = "trace_id"

Variables

View Source
var LevelStr = [7]string{}

Functions

func AppendLogExtras

func AppendLogExtras(ctx context.Context, extra map[string]string) context.Context

AppendLogExtras 注意,此函数并非并发安全,请勿在初始化之外等常见进行写入

func AppendLogKv

func AppendLogKv(ctx context.Context, key, value string) context.Context

AppendLogKv 注意,此函数并非并发安全,请勿在初始化之外等常见进行写入

func CtxDebug

func CtxDebug(ctx context.Context, format string, v ...interface{})

CtxDebug calls the default logger's CtxDebugf method.

func CtxError

func CtxError(ctx context.Context, format string, v ...interface{})

CtxError calls the default logger's CtxErrorf method.

func CtxFatal

func CtxFatal(ctx context.Context, format string, v ...interface{})

CtxFatal calls the default logger's CtxFatalf method and then os.Exit(1).

func CtxInfo

func CtxInfo(ctx context.Context, format string, v ...interface{})

CtxInfo calls the default logger's CtxInfof method.

func CtxNotice

func CtxNotice(ctx context.Context, format string, v ...interface{})

CtxNotice calls the default logger's CtxNoticef method.

func CtxTrace

func CtxTrace(ctx context.Context, format string, v ...interface{})

CtxTrace calls the default logger's CtxTracef method.

func CtxWarn

func CtxWarn(ctx context.Context, format string, v ...interface{})

CtxWarn calls the default logger's CtxWarnf method.

func Debug

func Debug(format string, v ...interface{})

Debug calls the default logger's Debugf method.

func Error

func Error(format string, v ...interface{})

Error calls the default logger's Errorf method.

func Fatal

func Fatal(format string, v ...interface{})

Fatal calls the default logger's Fatalf method and then os.Exit(1).

func GetAllCustomFields

func GetAllCustomFields(ctx context.Context) map[string]string

func GetGID

func GetGID() string

func GetPID

func GetPID() string

func Info

func Info(format string, v ...interface{})

Info calls the default logger's Infof method.

func Notice

func Notice(format string, v ...interface{})

Notice calls the default logger's Noticef method.

func SetLevel

func SetLevel(level Level)

SetLevel sets the level of logs below which logs will not be output. The default log level is LevelTrace. Note that this method is not concurrent-safe.

func SetLogFile

func SetLogFile(fileName string, ops ...LogfileOption)

SetLogFile sets log output to file and stdout. Use lumberjack to rolling file.

func SetLogger

func SetLogger(fullLogger klog.FullLogger)

func SetLoggerType

func SetLoggerType(t LoggerType)

SetLoggerType sets the logger type (must be called before logger initialization) Note: This should be called before any logging operations

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output of default logger. By default, it is stderr.

func SetProdEnv

func SetProdEnv()

func Trace

func Trace(format string, v ...interface{})

Trace calls the default logger's Tracef method.

func Warn

func Warn(format string, v ...interface{})

Warn calls the default logger's Warnf method.

func WithHertz

func WithHertz()

func WithKitex

func WithKitex()

Types

type Formatter

type Formatter struct {
}

Formatter implements logrus.Formatter interface.

func (*Formatter) Format

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

Format building log message.

type HLogger

type HLogger struct {
	*Logger
}

func (*HLogger) SetLevel

func (hl *HLogger) SetLevel(level hlog.Level)

type Level

type Level int

Level defines the priority of a log message. When a logger is configured with a level, any log message with a lower log level (smaller by integer comparison) will not be output.

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

The levels of logs.

func GetLogLevel

func GetLogLevel() Level

type LogfileOption

type LogfileOption interface {
	// contains filtered or unexported methods
}

LogfileOption is the only way to config log file option.

func WithMaxAge

func WithMaxAge(age int) LogfileOption

WithMaxAge set maximum days to keep expired files

func WithMaxBackups

func WithMaxBackups(backups int) LogfileOption

WithMaxBackups set maximum number of expired files to keep

func WithMaxSize

func WithMaxSize(size int) LogfileOption

WithMaxSize set log file's max size, MB

type Logger

type Logger struct {
	klog.FullLogger
	// contains filtered or unexported fields
}

Logger wraps different logger implementations

func GetLogger

func GetLogger() *Logger

type LoggerType

type LoggerType string

LoggerType defines the type of logger to use

const (
	LoggerTypeLogrus  LoggerType = "logrus"
	LoggerTypeZerolog LoggerType = "zerolog"
)

func GetLoggerType

func GetLoggerType() LoggerType

GetLoggerType returns the current logger type

Jump to

Keyboard shortcuts

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