logger

package
v0.0.0-...-72d088b Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MonthlyRolling  RollingFormat = "200601"
	DailyRolling                  = "20060102"
	HourlyRolling                 = "2006010215"
	MinutelyRolling               = "200601021504"
	SecondlyRolling               = "20060102150405"
)

RollingFormats

View Source
const (
	FrequencyHourly  = 0
	FrequencyDaily   = 1
	FrequencyMonthly = 2
)

Rotate frequencies

Variables

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

Errors

View Source
var (
	DefaultKit *kit
)

Functions

func AccessLog

func AccessLog(args ...interface{})

func AccessLogf

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

func BalanceLog

func BalanceLog(args ...interface{})

func BalanceLogf

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

func CrashLog

func CrashLog(args ...interface{})

func CrashLogf

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

func Debug

func Debug(args ...interface{})

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

func Debugf

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

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

func 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 Error

func Error(args ...interface{})

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

func Errorf

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

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

func 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 Fatal

func Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func Fatalf

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

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func Fatalw

func 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.

func GenLog

func GenLog(args ...interface{})

func GenLogf

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

func Info

func Info(args ...interface{})

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

func Infof

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

Infof uses fmt.Sprintf to log a templated message.

func Infow

func 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 InfraLog

func InfraLog(args ...interface{})

func InfraLogf

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

func MilliSecondTimeEncoder

func MilliSecondTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func NewKit

func NewKit(access *Logger, balance *Logger, slow *Logger, gen *Logger, crash *Logger, infra *Logger) *kit

func NewTimeEncoder

func NewTimeEncoder(timeFormat string) func(time.Time, zapcore.PrimitiveArrayEncoder)

func SlowLog

func SlowLog(args ...interface{})

func SlowLogf

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

func Sync

func Sync() error

Sync flushes any buffered log entries.

func Warn

func Warn(args ...interface{})

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

func Warnf

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

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

func 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.

Types

type IOWriter

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

IOWriter : On-disk writer with rotator

func NewIOWriter

func NewIOWriter() *IOWriter

NewIOWriter create rolling writer

func (*IOWriter) Sync

func (w *IOWriter) Sync()

Sync data on-land

func (*IOWriter) Write

func (w *IOWriter) Write(p []byte) (int, error)

Write data to IOWriter

type Level

type Level string
const (
	DebugLevel Level = "DEBUG"
	// InfoLevel is the default logging priority.
	// General operational entries about what's going on inside the application.
	InfoLevel Level = "INFO"
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel Level = "WARN"
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel Level = "ERROR"
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
	FatalLevel Level = "FATAL"
)

type Logger

type Logger struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}
var (

	// DefaultLogger implementated Logger, can override by any instance
	DefaultLogger *Logger
)

func For

func For(ctx context.Context, args ...interface{}) *Logger

For 注入 context

func New

func New(opts ...*Options) *Logger

func With

func With(args ...interface{}) *Logger

With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.

For example,

 sugaredLogger.With(
   "hello", "world",
   "failure", errors.New("oh no"),
   Stack(),
   "count", 42,
   "user", User{Name: "alice"},
)

is the equivalent of

unsugared.With(
  String("hello", "world"),
  String("failure", "oh no"),
  Stack(),
  Int("count", 42),
  Object("user", User{Name: "alice"}),
)

Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.

func (*Logger) For

func (l *Logger) For(ctx context.Context, args ...interface{}) *Logger

func (*Logger) Init

func (l *Logger) Init() error

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) Logger

func (l *Logger) Logger() *log.Logger

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel set logger level

func (*Logger) SetLogPrefix

func (l *Logger) SetLogPrefix(prefix string)

func (*Logger) SetOutput

func (l *Logger) SetOutput() error

func (*Logger) SetPrintLevel

func (l *Logger) SetPrintLevel(printLevel bool)

func (*Logger) SetTimeFmt

func (l *Logger) SetTimeFmt(fmt string) error

func (*Logger) String

func (l *Logger) String() string

func (*Logger) With

func (l *Logger) With(args ...interface{}) *Logger

type Options

type Options struct {
	// The logging level the logger should log at. default is `InfoLevel`
	Level Level
	// Alternative options
	Context context.Context
	// EnableConsole display logs to standard output
	EnableConsole bool
	// DisableOnDisk disable rolling file
	DisableOnDisk bool
	// BasePath defines base path of log file
	BasePath string
	//  logger file name
	FileName string

	CallerSkip int
}

Options : Logger options

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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