logger

package
v1.6.0-beta Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 173

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(template string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(template string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(template string, args ...interface{})

func Info

func Info(args ...interface{})

Info logs a message at the info log level.

func Infof

func Infof(template string, args ...interface{})

func Init

func Init(opts ...Option) error

func Log

func Log(level Level, v ...interface{})

func Logf

func Logf(level Level, format string, v ...interface{})

func NewContext

func NewContext(ctx context.Context, l *Helper) context.Context

func String

func String() string

func Trace

func Trace(args ...interface{})

func Tracef

func Tracef(template string, args ...interface{})

func V

func V(lvl Level, log Logger) bool

Returns true if the given level is at or lower the current logger level

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(template string, args ...interface{})

Types

type Helper

type Helper struct {
	Logger
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) (*Helper, bool)

func NewHelper

func NewHelper(log Logger) *Helper

func (*Helper) Debug

func (h *Helper) Debug(args ...interface{})

func (*Helper) Debugf

func (h *Helper) Debugf(template string, args ...interface{})

func (*Helper) Error

func (h *Helper) Error(args ...interface{})

func (*Helper) Errorf

func (h *Helper) Errorf(template string, args ...interface{})

func (*Helper) Fatal

func (h *Helper) Fatal(args ...interface{})

func (*Helper) Fatalf

func (h *Helper) Fatalf(template string, args ...interface{})

func (*Helper) Info

func (h *Helper) Info(args ...interface{})

func (*Helper) Infof

func (h *Helper) Infof(template string, args ...interface{})

func (*Helper) Trace

func (h *Helper) Trace(args ...interface{})

func (*Helper) Tracef

func (h *Helper) Tracef(template string, args ...interface{})

func (*Helper) Warn

func (h *Helper) Warn(args ...interface{})

func (*Helper) Warnf

func (h *Helper) Warnf(template string, args ...interface{})

func (*Helper) WithError

func (h *Helper) WithError(err error) *Helper

func (*Helper) WithFields

func (h *Helper) WithFields(fields map[string]interface{}) *Helper

type Level

type Level int8
const (
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel Level = iota - 2
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// InfoLevel is the default logging priority.
	// General operational entries about what's going on inside the application.
	InfoLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
	FatalLevel
)

func GetLevel

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) Enabled

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) LevelForGorm

func (l Level) LevelForGorm() int

LevelForGorm 转换成gorm日志级别

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	// Init initialises options
	Init(options ...Option) error
	// Options The Logger options
	Options() Options
	// Fields set fields to always be logged
	Fields(fields map[string]interface{}) Logger
	// Log writes a log entry
	Log(level Level, v ...interface{})
	// Logf writes a formatted log entry
	Logf(level Level, format string, v ...interface{})
	// String returns the name of logger
	String() string
}

Logger is a generic logging interface

var (
	// DefaultLogger logger
	DefaultLogger Logger
)

func Fields

func Fields(fields map[string]interface{}) Logger

func NewLogger

func NewLogger(opts ...Option) Logger

NewLogger 创建一个新的日志记录器 NewLogger creates a new logger

type Option

type Option func(*Options)

Option is a function that configures the logger options Option 是一个配置日志记录器选项的函数

func SetOption

func SetOption(k, v interface{}) Option

SetOption sets a custom option SetOption 设置自定义选项

func WithCallerSkipCount

func WithCallerSkipCount(c int) Option

WithCallerSkipCount sets frame count to skip WithCallerSkipCount 设置要跳过的帧数

func WithFields

func WithFields(fields map[string]interface{}) Option

WithFields sets default fields for the logger WithFields 设置日志记录器的默认字段

func WithLevel

func WithLevel(level Level) Option

WithLevel sets default level for the logger WithLevel 设置日志记录器的默认级别

func WithName added in v1.2.3

func WithName(name string) Option

WithName sets name for logger WithName 设置日志记录器的名称

func WithOutput

func WithOutput(out io.Writer) Option

WithOutput sets default output writer for the logger WithOutput 设置日志记录器的默认输出写入器

type Options

type Options struct {
	// Level is the logging level the logger should log at. default is `InfoLevel`
	// Level 是日志记录器的日志级别,默认是 `InfoLevel`
	Level Level
	// Fields are fields to always be logged
	// Fields 是始终要记录的字段
	Fields map[string]interface{}
	// Out is the output writer for the logger. default is `os.Stderr`
	// Out 是日志记录器的输出写入器,默认是 `os.Stderr`
	Out io.Writer
	// CallerSkipCount is the frame count to skip for file:line info
	// CallerSkipCount 是跳过的帧数,用于文件:行信息
	CallerSkipCount int
	// Context is alternative options
	// Context 是替代选项
	Context context.Context
	// Name is the logger name
	// Name 是日志记录器的名称
	Name string
}

Options are logger options Options 是日志记录器选项

func DefaultOptions added in v1.6.0

func DefaultOptions() Options

DefaultOptions returns default options DefaultOptions 返回默认选项

Directories

Path Synopsis
plugins
zap

Jump to

Keyboard shortcuts

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