zapcore

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel = iota + 1
	// 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
)
View Source
const (
	MonthlyRolling  RollingFormat = "200601"
	DailyRolling                  = "20060102"
	HourlyRolling                 = "2006010215"
	MinutelyRolling               = "200601021504"
	SecondlyRolling               = "20060102150405"
)

RollingFormats

Variables

View Source
var (
	ErrClosedRollingFile = errors.New("rolling file is closed")
	ErrBuffer            = errors.New("buffer exceeds the limit")
)

Errors

View Source
var (
	// ErrLogPathNotSet is an error that indicates the log path is not set.
	ErrLogPathNotSet = errors.New("log path must be set")
)

Functions

func Must

func Must(err error)

Must checks if err is nil, otherwise logs the err and exits.

Types

type Encoder

type Encoder string
const (
	JsonEncoder    Encoder = "json"
	ConsoleEncoder Encoder = "console"
)

func (*Encoder) IsConsole

func (e *Encoder) IsConsole() bool

IsConsole Whether console encoder.

func (*Encoder) IsJson

func (e *Encoder) IsJson() bool

IsJson Whether json encoder.

func (*Encoder) String

func (e *Encoder) String() string

type KzLog

type KzLog struct {
	// contains filtered or unexported fields
}

KzLog default logger achieve

func New

func New(opts ...Options) *KzLog

func (*KzLog) AddHooks

func (l *KzLog) AddHooks(hooks ...func(entry zapcore.Entry) error)

func (*KzLog) Debug

func (l *KzLog) Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func (*KzLog) Debugf

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

Debugf uses fmt.Sprintf to log a templated message.

func (*KzLog) Debugw

func (l *KzLog) Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

When debug-level logging is disabled, this is much faster than

s.With(keysAndValues).Debug(msg)

func (*KzLog) Error

func (l *KzLog) Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func (*KzLog) Errorf

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

Errorf uses fmt.Sprintf to log a templated message.

func (*KzLog) Errorw

func (l *KzLog) Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*KzLog) Fatal

func (l *KzLog) Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。

func (*KzLog) Fatalf

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

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。

func (*KzLog) Fatalw

func (l *KzLog) Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。

func (*KzLog) Info

func (l *KzLog) Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func (*KzLog) Infof

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

Infof uses fmt.Sprintf to log a templated message.

func (*KzLog) Infow

func (l *KzLog) Infow(msg string, keysAndValues ...interface{})

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*KzLog) LevelEnablerFunc

func (l *KzLog) LevelEnablerFunc(level zapcore.Level) LevelEnablerFunc

func (*KzLog) Log

func (l *KzLog) Log(level Level, template string, fmtArgs []interface{}, context []interface{})

func (*KzLog) Options

func (l *KzLog) Options() *Option

func (*KzLog) SetLevel

func (l *KzLog) SetLevel(lv kiko_logger.Level)

func (*KzLog) StdLog

func (l *KzLog) StdLog() *std.Logger

func (*KzLog) Sync

func (l *KzLog) Sync() error

func (*KzLog) Warn

func (l *KzLog) Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func (*KzLog) Warnf

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

Warnf uses fmt.Sprintf to log a templated message.

func (*KzLog) Warnw

func (l *KzLog) Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*KzLog) WithCallDepth

func (l *KzLog) WithCallDepth(callDepth int) kiko_logger.Logger

WithCallDepth with logger call depth.

func (*KzLog) WithContext

func (l *KzLog) WithContext(ctx context.Context) kiko_logger.Logger

WithContext with context

func (*KzLog) WithError

func (l *KzLog) WithError(err error) kiko_logger.Logger

WithError with logger error

func (*KzLog) WithFields

func (l *KzLog) WithFields(fields map[string]interface{}) kiko_logger.Logger

WithFields set fields to always be logged

type Level

type Level int8

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a level string into a logger Level value.

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) String

func (l Level) String() string

type LevelEnablerFunc

type LevelEnablerFunc func(zapcore.Level) bool

LevelEnablerFunc is a convenient way to implement zapcore.LevelEnabler with an anonymous function.

It's particularly useful when splitting log output between different outputs (e.g., standard error and standard out). For sample code, see the package-level AdvancedConfiguration example.

func (LevelEnablerFunc) Enabled

func (f LevelEnablerFunc) Enabled(lvl zapcore.Level) bool

Enabled calls the wrapped function.

type Option

type Option struct {
	// contains filtered or unexported fields
}

func (Option) Level

func (o Option) Level() Level

Level Get log level.

type Options

type Options func(o *Option)

func WithBasePath

func WithBasePath(path string) Options

WithBasePath set base path.

func WithCallerSkip

func WithCallerSkip(skip int) Options

WithCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option). When building wrappers around the Logger and SugaredLogger, supplying this Option prevents base from always reporting the wrapper code as the caller.

func WithConsole

func WithConsole(enableConsole bool) Options

WithConsole enable console.

func WithDisableDisk

func WithDisableDisk(disableDisk bool) Options

WithDisableDisk disable disk.

func WithEncoder

func WithEncoder(encoder Encoder) Options

WithEncoder set logger Encoder

func WithEncoderConfig

func WithEncoderConfig(encoderConfig zapcore.EncoderConfig) Options

WithEncoderConfig set logger encoderConfig

func WithFields

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

WithFields set default fields for the logger

func WithFilename

func WithFilename(filename string) Options

WithFilename Logger filename.

func WithLevel

func WithLevel(lv Level) Options

WithLevel set base path.

func WithNamespace

func WithNamespace(name string) Options

WithNamespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.

This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.

type RollingFile

type RollingFile struct {
	// contains filtered or unexported fields
}

RollingFile : Defination of rolling

func NewRollingFile

func NewRollingFile(basePath string, rolling RollingFormat) (*RollingFile, error)

NewRollingFile create new rolling

func (*RollingFile) Close

func (r *RollingFile) Close() error

Close syncer file

func (*RollingFile) SetRolling

func (r *RollingFile) SetRolling(fmt RollingFormat)

SetRolling : Set rolling format

func (*RollingFile) Sync

func (r *RollingFile) Sync() error

Sync buffered data to writer

func (*RollingFile) Write

func (r *RollingFile) Write(b []byte) (n int, err error)

type RollingFormat

type RollingFormat string

RollingFormat : Type hinting

Jump to

Keyboard shortcuts

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