logger

package
v0.0.0-...-8845b87 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(cfg Config) error

InitLogger initializes a zap logger from user config.

Types

type Config

type Config struct {
	Level string `yaml:"level"`
}

Log represents a logging configuration.

type Field

type Field = zap.Field

Field represents filed of zap logger.

func Any

func Any(key string, value interface{}) Field

Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.

func Error

func Error(err error) Field

Error is shorthand for the common idiom NamedError("error", err).

func Int32

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Reflect

func Reflect(key string, val interface{}) Field

Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.

If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.

func Stack

func Stack() Field

Stack constructs a field that stores a stacktrace of the current goroutine under provided key. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.

func String

func String(key string, val string) Field

String constructs a field with the given key and value.

func Uint16

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint32

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

type Logger

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

Logger is wrapper for zap logger with module, it is singleton.

func GetLogger

func GetLogger(module string) *Logger

GetLogger return logger with module name.

func L

func L() *Logger

L returns under zap logger.

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...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 (*Logger) Error

func (l *Logger) Error(msg string, fields ...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 (*Logger) Errorf

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

Errorf uses fmt.Sprintf to log a templated message.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...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.

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...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 (*Logger) Infof

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

Infof uses fmt.Sprintf to log a templated message.

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...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 (*Logger) With

func (l *Logger) With(fields ...Field) *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.

Jump to

Keyboard shortcuts

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