log

package
v0.0.0-...-a2e0f46 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package log defines the logger for the sdk.

Index

Constants

This section is empty.

Variables

View Source
var LevelNames = map[string]Level{
	"trace": LevelTrace,
	"debug": LevelDebug,
	"info":  LevelInfo,
	"warn":  LevelWarn,
	"error": LevelError,
	"fatal": LevelFatal,
}

LevelNames log level name map

Functions

func Debug

func Debug(args ...interface{})

Debug logs to DEBUG level log. Arguments are handled in the manner of fmt.Print.

func Debugf

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

Debugf logs to DEBUG level log. Arguments are handled in the manner of fmt.Printf.

func EnableTrace

func EnableTrace()

EnableTrace enables trace level log.

func Error

func Error(args ...interface{})

Error logs to ERROR level log. Arguments are handled in the manner of fmt.Print.

func Errorf

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

Errorf logs to ERROR level log. Arguments are handled in the manner of fmt.Printf.

func Fatal

func Fatal(args ...interface{})

Fatal logs to ERROR level log. Arguments are handled in the manner of fmt.Print. that all Fatal logs will exit with os.Exit(1).

func Fatalf

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

Fatalf logs to ERROR level log. Arguments are handled in the manner of fmt.Printf.

func Info

func Info(args ...interface{})

Info logs to INFO level log. Arguments are handled in the manner of fmt.Print.

func Infof

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

Infof logs to INFO level log. Arguments are handled in the manner of fmt.Print.

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel set log level

func SetLogPath

func SetLogPath(path string) error

SetLogPath set log path

func SetLogger

func SetLogger(logger Logger)

SetLogger sets the default logger to the given logger.

func Trace

func Trace(args ...interface{})

Trace logs to TRACE level log. Arguments are handled in the manner of fmt.Print.

func Tracef

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

Tracef logs to TRACE level log. Arguments are handled in the manner of fmt.Printf.

func Warn

func Warn(args ...interface{})

Warn logs to WARNING level log. Arguments are handled in the manner of fmt.Print.

func Warnf

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

Warnf logs to WARNING level log. Arguments are handled in the manner of fmt.Printf.

Types

type Level

type Level int

Level log level

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

log level const

type Logger

type Logger interface {
	// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Print.
	Trace(args ...interface{})
	// Tracef logs to TRACE log. Arguments are handled in the manner of fmt.Printf.
	Tracef(format string, args ...interface{})
	// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print.
	Debug(args ...interface{})
	// Debugf logs to DEBUG log. Arguments are handled in the manner of fmt.Printf.
	Debugf(format string, args ...interface{})
	// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
	Info(args ...interface{})
	// Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
	Infof(format string, args ...interface{})
	// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print.
	Warn(args ...interface{})
	// Warnf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
	Warnf(format string, args ...interface{})
	// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
	Error(args ...interface{})
	// Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
	Errorf(format string, args ...interface{})
	// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
	// that all Fatal logs will exit with os.Exit(1).
	// Implementations may also call os.Exit() with a non-zero exit code.
	Fatal(args ...interface{})
	// Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
	Fatalf(format string, args ...interface{})

	// Sync calls the underlying Core's Sync method, flushing any buffered log entries.
	// Applications should take care to call Sync before exiting
	Sync() error

	// // WithFields sets the user-defined data to the log and return a new Logger.
	WithFields(fields ...string) Logger
}

Logger is an interface that abstracts behavior of the logger.

func NewLogger

func NewLogger(config *OutputConfig) Logger

NewLogger will return a configured zap logger.

func WithFields

func WithFields(fields ...string) Logger

WithFields is the proxy to call the WithFields of defaultLogger.

type OutputConfig

type OutputConfig struct {
	// LogPath is the path for the log.
	LogPath string
	// Level is the log level.
	Level string
	// MaxSize is the max size for a rolling log.
	MaxSize int
	// MaxBackups is the maximum number of old log files to retain.
	MaxBackups int
	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.
	MaxAge int
}

OutputConfig defines the output config which can be reconfigured by user.

type ZapLogWrapper

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

ZapLogWrapper implements Logger interface based on the underlying zapLog.

func (*ZapLogWrapper) Debug

func (z *ZapLogWrapper) Debug(args ...interface{})

Debug logs to DEBUG log, Arguments are handled in the manner of fmt.Print

func (*ZapLogWrapper) Debugf

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

Debugf logs to DEBUG log, Arguments are handled in the manner of fmt.Printf

func (*ZapLogWrapper) Error

func (z *ZapLogWrapper) Error(args ...interface{})

Error logs to ERROR log, Arguments are handled in the manner of fmt.Print

func (*ZapLogWrapper) Errorf

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

Errorf logs to ERROR log, Arguments are handled in the manner of fmt.Printf

func (*ZapLogWrapper) Fatal

func (z *ZapLogWrapper) Fatal(args ...interface{})

Fatal logs to FATAL log, Arguments are handled in the manner of fmt.Print

func (*ZapLogWrapper) Fatalf

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

Fatalf logs to FATAL log, Arguments are handled in the manner of fmt.Printf

func (*ZapLogWrapper) GetLogger

func (z *ZapLogWrapper) GetLogger() Logger

GetLogger returns the wrapped zap looger.

func (*ZapLogWrapper) Info

func (z *ZapLogWrapper) Info(args ...interface{})

Info logs to INFO log, Arguments are handled in the manner of fmt.Print

func (*ZapLogWrapper) Infof

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

Infof logs to INFO log, Arguments are handled in the manner of fmt.Printf

func (*ZapLogWrapper) Sync

func (z *ZapLogWrapper) Sync() error

Sync calls the zap defaultLogger's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func (*ZapLogWrapper) Trace

func (z *ZapLogWrapper) Trace(args ...interface{})

Trace logs to TRACE log, Arguments are handled in the manner of fmt.Print

func (*ZapLogWrapper) Tracef

func (z *ZapLogWrapper) Tracef(format string, args ...interface{})

Tracef logs to TRACE log, Arguments are handled in the manner of fmt.Printf

func (*ZapLogWrapper) Warn

func (z *ZapLogWrapper) Warn(args ...interface{})

Warn logs to WARNING log, Arguments are handled in the manner of fmt.Print

func (*ZapLogWrapper) Warnf

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

Warnf logs to WARNING log, Arguments are handled in the manner of fmt.Printf

func (*ZapLogWrapper) WithFields

func (z *ZapLogWrapper) WithFields(fields ...string) Logger

WithFields sets the user-defined data to the log and return a new Logger.

Jump to

Keyboard shortcuts

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