log

package
v0.0.0-...-dfe2c77 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, kvs ...any)

Debug logs a message at the Debug level.

func Error

func Error(msg string, kvs ...any)

Error logs a message at the Error level.

func Fatal

func Fatal(msg string, kvs ...any)

Fatal logs a message at the Fatal level and exits the application.

func Info

func Info(msg string, kvs ...any)

Info logs a message at the Info level.

func Init

func Init(opts *Options)

Init, initializes the global logger with the given options.

func New

func New(opts *Options) *zapLogger

func Panic

func Panic(msg string, kvs ...any)

Panic logs a message at the Panic level and panics.

func Sync

func Sync()

Sync calls the Sync method of the underlying zap.Logger to refresh the cached logs to the disk file. The main program needs to call Sync before exiting.

func Warn

func Warn(msg string, kvs ...any)

Warn logs a message at the Warn level.

Types

type Logger

type Logger interface {
	Debug(msg string, kvs ...any)

	Info(msg string, kvs ...any)

	Warn(msg string, kvs ...any)

	Error(msg string, kvs ...any)

	// Fatal logs a message at the Fatal level and exits the application.
	Fatal(msg string, kvs ...any)

	// Panic logs a message at the Panic level and panics.
	Panic(msg string, kvs ...any)

	// Sync flushes any buffered log entries.
	Sync()
}

Logger is an interface that defines the methods for logging.

func W

func W(ctx context.Context) Logger

------ Add context to log ------

type Options

type Options struct {
	// DisableCaller specifies whether to disable the caller information.
	// If set to false (the default value), the file name and line number where the call log is located will be displayed in the log,
	// for example :" caller":"main.go:42".
	DisableCaller bool

	// DisableStacktrace specifies whether to disable the stack trace information.
	// If set to false (the default value), the stack trace information will be displayed in the log when the log level is panic or fatal.
	// For example, if the log level is panic, the stack trace information will be displayed in the log.
	DisableStacktrace bool

	// Level specifies the log level.
	// The default value is "info".
	// The log level can be set to "debug", "info", "warn", "error", "panic", or "fatal".
	Level string

	// Format specifies the log format.
	// The default value is "console".
	// The log format can be set to "json" or "console".
	Format string

	// OutputPaths specifies the output path of the log.
	// The default value is "stdout".
	// The output path can be set to "stdout", "stderr", or a file path.
	// For example, "stdout" will output the log to the standard output,
	// "stderr" will output the log to the standard error, and "/var/log/app.log" will output the log to the file "/var/log/app.log".
	// The output path can also be set to multiple paths, for example, "stdout,stderr,/var/log/app.log".
	// In this case, the log will be output to the standard output, standard error, and the file "/var/log/app.log".
	OutputPaths []string
}

Options defines the options for the logger.

func NewOptions

func NewOptions() *Options

Jump to

Keyboard shortcuts

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