logger

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultLogTimeFormat = "2006-01-02T15:04:05.000000Z07:00"
	// DefaultLogFormat is the default format of the log.
	DefaultLogFormat = "text"
	DefaultLogLevel  = zapcore.InfoLevel

	// DefaultLogMaxSize is the default size of log files.
	DefaultLogMaxSize = 300 // MB
)
View Source
const (
	// TraceIDKey is the logging context key used for identifying unique traces.
	TraceIDKey = "trace_id"

	// OperationNameKey is the logging context key used for identifying name of an operation.
	OperationNameKey = "op_name"

	// OperationEventKey is the logging context key used for identifying a notable
	// event during the course of an operation.
	OperationEventKey = "op_event"

	// OperationElapsedKey is the logging context key used for identifying time elapsed to finish an operation.
	OperationElapsedKey = "op_elapsed"

	// DBInstanceKey is the logging context key used for identifying name of the relevant database.
	DBInstanceKey = "db_instance"

	// DBRetentionPolicyKey is the logging context key used for identifying name of the relevant retention policy.
	DBRetentionPolicyKey = "db_rp"

	// DBShardGroupKey is the logging context key used for identifying relevant shard group.
	DBShardGroupKey = "db_shard_group"

	// DBShardIDKey is the logging context key used for identifying name of the relevant shard number.
	DBShardIDKey = "db_shard_id"
)

Variables

This section is empty.

Functions

func Database

func Database(name string) zapcore.Field

Database returns a field for tracking the name of a database.

func Debug added in v1.0.1

func Debug(msg string, fields ...zap.Field)

Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func DurationLiteral added in v1.0.1

func DurationLiteral(key string, val time.Duration) zapcore.Field

DurationLiteral represents a duration literal from a key and time duration.

func Error added in v1.0.1

func Error(msg string, fields ...zap.Field)

Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func Fatal added in v1.0.1

func Fatal(msg string, fields ...zap.Field)

Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Info added in v1.0.1

func Info(msg string, fields ...zap.Field)

Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func InitZapLogger

func InitZapLogger(cfg *Config) error

func L added in v1.0.1

func L() *zap.Logger

L returns the global Logger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.

func NewLoggerWithConfigAndWriter added in v1.0.1

func NewLoggerWithConfigAndWriter(config *Config, w io.Writer, opts ...zap.Option) (*zap.Logger, error)

NewLoggerWithConfigAndWriter creates a new zap.Logger with a Config and an io.Writer

func NewLoggerWithWriter added in v1.0.1

func NewLoggerWithWriter(w io.Writer, opts ...zap.Option) *zap.Logger

NewLoggerWithWriter creates a new zap.Logger with an io.Writer

func NewOperation

func NewOperation(log *zap.Logger, msg, name string, fields ...zapcore.Field) (*zap.Logger, func())

NewOperation uses the exiting log to create a new logger with context containing a trace id and the operation. Prior to returning, a standardized message is logged indicating the operation has started. The returned function should be called when the operation concludes in order to log a corresponding message which includes an elapsed time and that the operation has ended.

func OperationElapsed

func OperationElapsed(d time.Duration) zapcore.Field

OperationElapsed returns a field for tracking the duration of an operation.

func OperationEventEnd

func OperationEventEnd() zapcore.Field

OperationEventEnd returns a field for tracking the end of an operation.

func OperationEventStart

func OperationEventStart() zapcore.Field

OperationEventStart returns a field for tracking the start of an operation.

func OperationName

func OperationName(name string) zapcore.Field

OperationName returns a field for tracking the name of an operation.

func Panic added in v1.0.1

func Panic(msg string, fields ...zap.Field)

Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then panics, even if logging at PanicLevel is disabled.

func RetentionPolicy

func RetentionPolicy(name string) zapcore.Field

RetentionPolicy returns the retention policy.

func S added in v1.0.1

func S() *zap.SugaredLogger

S returns the global SugaredLogger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.

func Shard

func Shard(id uint64) zapcore.Field

Shard returns a field for tracking the shard identifier.

func ShardGroup

func ShardGroup(id uint64) zapcore.Field

ShardGroup returns a field for tracking the shard group identifier.

func TraceID

func TraceID(id string) zapcore.Field

TraceID returns a field for tracking the trace identifier.

func Warn added in v1.0.1

func Warn(msg string, fields ...zap.Field)

Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func With added in v1.0.1

func With(fields ...zap.Field) *zap.Logger

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

Types

type Config

type Config struct {
	zaputil.Config
}

func NewDefaultLogConfig

func NewDefaultLogConfig() *Config

func NewLogConfig

func NewLogConfig(level zapcore.Level, format string, fileCfg LogFileConfig, disableTimestamp bool, opts ...func(*zaputil.Config)) *Config

NewLogConfig "comment"

type LogFileConfig

type LogFileConfig struct {
	zaputil.FileConfig
}

func NewLogFileConfig

func NewLogFileConfig(maxSize uint) LogFileConfig

NewLogFileConfig "comment"

Jump to

Keyboard shortcuts

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