log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package log is a log package used by onex project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

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

Debugf 输出 debug 级别的日志.

func Debugw

func Debugw(msg string, keyvals ...interface{})

Debugw 输出 debug 级别的日志.

func Errorf

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

Errorf 输出 error 级别的日志.

func Errorw

func Errorw(err error, msg string, keyvals ...interface{})

Errorw 输出 error 级别的日志.

func Fatalf

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

Fatalf 输出 fatal 级别的日志.

func Fatalw

func Fatalw(msg string, keyvals ...interface{})

Fatalw 输出 fatal 级别的日志.

func Infof

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

Infof 输出 info 级别的日志.

func Infow

func Infow(msg string, keyvals ...interface{})

Infow 输出 info 级别的日志.

func Init

func Init(opts *Options)

Init 使用指定的选项初始化 Logger.

func NewLogger

func NewLogger(opts *Options) *zapLogger

NewLogger 根据传入的 opts 创建 Logger.

func Panicf

func Panicf(format string, args ...interface{})

Panicf 输出 panic 级别的日志.

func Panicw

func Panicw(msg string, keyvals ...interface{})

Panicw 输出 panic 级别的日志.

func Sync

func Sync()

Sync 调用底层 zap.Logger 的 Sync 方法,将缓存中的日志刷新到磁盘文件中. 主程序需要在退出前调用 Sync.

func Warnf

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

Warnf 输出 warning 级别的日志.

func Warnw

func Warnw(msg string, keyvals ...interface{})

Warnw 输出 warning 级别的日志.

func WithContext

func WithContext(ctx context.Context, keyvals ...interface{}) context.Context

WithContext returns a copy of context in which the log value is set.

Types

type Field

type Field = zapcore.Field

type KratosLogger

type KratosLogger interface {
	// Log implements is used to github.com/go-kratos/kratos/v2/log.Logger interface.
	Log(level krtlog.Level, keyvals ...interface{}) error
}

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Debugw(msg string, keyvals ...interface{})
	Infof(format string, args ...interface{})
	Infow(msg string, keyvals ...interface{})
	Warnf(format string, args ...interface{})
	Warnw(msg string, keyvals ...interface{})
	Errorf(format string, args ...interface{})
	Errorw(err error, msg string, keyvals ...interface{})
	Panicf(format string, args ...interface{})
	Panicw(msg string, keyvals ...interface{})
	Fatalf(format string, args ...interface{})
	Fatalw(msg string, keyvals ...interface{})
	With(fields ...Field) Logger
	AddCallerSkip(skip int) Logger
	Sync()

	// integrate other loggers
	krtlog.Logger
	gormlogger.Interface
}

Logger 定义了 onex 项目的日志接口. 该接口只包含了支持的日志记录方法.

func AddCallerSkip

func AddCallerSkip(skip int) Logger

func C

func C(ctx context.Context) Logger

C represents for `FromContext` with empty keyvals.

func Default

func Default() Logger

func FromContext

func FromContext(ctx context.Context, keyvals ...interface{}) Logger

FromContext returns a logger with predefined values from a context.Context.

func With

func With(fields ...Field) Logger

type Options

type Options struct {
	// DisableCaller specifies whether to include caller information in the log.
	DisableCaller bool `json:"disable-caller,omitempty" mapstructure:"disable-caller"`
	// DisableStacktrace specifies whether to record a stack trace for all messages at or above panic level.
	DisableStacktrace bool `json:"disable-stacktrace,omitempty" mapstructure:"disable-stacktrace"`
	// EnableColor specifies whether to output colored logs.
	EnableColor bool `json:"enable-color"       mapstructure:"enable-color"`
	// Level specifies the minimum log level. Valid values are: debug, info, warn, error, dpanic, panic, and fatal.
	Level string `json:"level,omitempty" mapstructure:"level"`
	// Format specifies the log output format. Valid values are: console and json.
	Format string `json:"format,omitempty" mapstructure:"format"`
	// OutputPaths specifies the output paths for the logs.
	OutputPaths []string `json:"output-paths,omitempty" mapstructure:"output-paths"`
}

Options contains configuration options for logging.

func NewOptions

func NewOptions() *Options

NewOptions creates a new Options object with default values.

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags adds command line flags for the configuration.

func (*Options) Validate

func (o *Options) Validate() []error

Validate verifies flags passed to LogsOptions.

Jump to

Keyboard shortcuts

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