log

package
v0.2.1-alpha.4 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel = types.DebugLevel

	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel = types.InfoLevel

	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel = types.WarnLevel

	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel = types.ErrorLevel

	// PanicLevel level. Logs and then calls panic with the message passed to Debug, Info, ...
	PanicLevel = types.PanicLevel
)
View Source
const (
	CtxKeyBucketName = "bucket_name"
	CtxKeyObjectName = "object_name"
	CtxKeyObjectID   = "object_id"
	CtxKeyTask       = "task_key"
)

Variables

This section is empty.

Functions

func Context

func Context(ctx context.Context, opts ...interface{}) context.Context

func CtxDebug

func CtxDebug(ctx context.Context, args ...interface{})

CtxDebug uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.

func CtxDebugf

func CtxDebugf(ctx context.Context, fmt string, args ...interface{})

CtxDebugf uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.

func CtxDebugw

func CtxDebugw(ctx context.Context, msg string, kvs ...interface{})

CtxDebugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.

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

s.With(keysAndValues).CtxDebug(msg)

func CtxError

func CtxError(ctx context.Context, args ...interface{})

CtxError uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.

func CtxErrorf

func CtxErrorf(ctx context.Context, fmt string, args ...interface{})

CtxErrorf uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.

func CtxErrorw

func CtxErrorw(ctx context.Context, msg string, kvs ...interface{})

CtxErrorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.

func CtxInfo

func CtxInfo(ctx context.Context, args ...interface{})

CtxInfo uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.

func CtxInfof

func CtxInfof(ctx context.Context, fmt string, args ...interface{})

CtxInfof uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.

func CtxInfow

func CtxInfow(ctx context.Context, msg string, kvs ...interface{})

CtxInfow logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.

func CtxPanic

func CtxPanic(ctx context.Context, args ...interface{})

CtxPanic uses fmt.Sprint to construct and log a message, then panics. The metaInfo in Context will be appended to message as fields.

func CtxPanicf

func CtxPanicf(ctx context.Context, fmt string, args ...interface{})

CtxPanicf uses fmt.Sprintf to log a templated message, then panics. The metaInfo in Context will be appended to message as fields.

func CtxPanicw

func CtxPanicw(ctx context.Context, msg string, kvs ...interface{})

CtxPanicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.

func CtxWarn

func CtxWarn(ctx context.Context, args ...interface{})

CtxWarn uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.

func CtxWarnf

func CtxWarnf(ctx context.Context, fmt string, args ...interface{})

CtxWarnf uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.

func CtxWarnw

func CtxWarnw(ctx context.Context, msg string, kvs ...interface{})

CtxWarnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.

func Debug

func Debug(args ...interface{})

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

func Debugf

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

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

func Debugw(msg string, kvs ...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(fmt string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

func Errorw(msg string, kvs ...interface{})

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

func Info

func Info(args ...interface{})

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

func Infof

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

Infof uses fmt.Sprintf to log a templated message.

func Infow

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

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

func Init

func Init(lvl Level, path string)

Init auto setting level and creating log directory

func Panic

func Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func Panicf

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

Panicf uses fmt.Sprintf to log a templated message, then panics.

func Panicw

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

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

func SetLevel

func SetLevel(lvl Level)

SetLevel resets enabled log level

func SetLogger

func SetLogger(newLogger Logger)

NOTE: this func isn't thread safe

func SetWriter

func SetWriter(w types.AsyncWriter)

SetWriter resets log writer

func StandardizePath

func StandardizePath(filePath, serviceName string) string

StandardizePath is meant to decorate given file path by nodeIP/localIP/serviceName so that the returned path is consistent and unified throughout all services under node-real org The path after decoration will be `<file_path>/<node_ip>/<local_ip>/<service_name>.log`

func Stop

func Stop()

Stop flushes any buffered log entries, then stops writer. This method should be called when program stopping. For example,

func main() {
  defer log.Stop()

  log.Init(lvl, path)
}

func Warn

func Warn(args ...interface{})

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

func Warnf

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

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

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

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

func WithValue

func WithValue(ctx context.Context, k, v string) context.Context

Types

type AsyncFileWriter

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

func NewAsyncFileWriter

func NewAsyncFileWriter(filePath string, bufSize int64) *AsyncFileWriter

func (*AsyncFileWriter) Start

func (w *AsyncFileWriter) Start() error

func (*AsyncFileWriter) Stop

func (w *AsyncFileWriter) Stop() error

func (*AsyncFileWriter) Sync

func (w *AsyncFileWriter) Sync() error

func (*AsyncFileWriter) SyncWrite

func (w *AsyncFileWriter) SyncWrite(msg []byte)

func (*AsyncFileWriter) Write

func (w *AsyncFileWriter) Write(msg []byte) (n int, err error)

type AsyncWriter

type AsyncWriter types.AsyncWriter

AsyncWriter uses as log writer

func AddSync

func AddSync(w io.Writer) AsyncWriter

func NewMultiWriteSyncer

func NewMultiWriteSyncer(ws ...AsyncWriter) AsyncWriter

NewMultiWriteSyncer creates a WriteSyncer that duplicates its writes and sync calls, much like io.MultiWriter.

type HourTicker

type HourTicker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

func NewHourTicker

func NewHourTicker() *HourTicker

func (*HourTicker) Stop

func (ht *HourTicker) Stop()

func (*HourTicker) Ticker

func (ht *HourTicker) Ticker() <-chan time.Time

type Level

type Level = types.Level

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel parses level from string.

type Logger

type Logger = types.Logger

func With

func With(kvs ...interface{}) Logger

With adds a variadic number of fields to the logging context. It accepts 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. Note that the keys in key-value pairs should be strings. For example,

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

Directories

Path Synopsis
internal
zap

Jump to

Keyboard shortcuts

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