logger

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DEBUG has verbose message
	DEBUG = "debug"
	// INFO is default log level
	INFO = "info"
	// WARN is for logging messages about possible issues
	WARN = "warn"
	// ERROR is for logging errors
	ERROR = "error"
	// FATAL is for logging fatal messages. The sytem shutsdown after logging the message.
	FATAL = "fatal"
)

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string)

Debug log a debug message.

func Debugf

func Debugf(ctx context.Context, template string, args ...any)

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

func Debugw(ctx context.Context, msg string, keysAndValues ...any)

Debugw logs a message with some additional context, With key and values, example: log.Debugw("message", "url", url, "attempt", 3) Keys in key-value pairs should be strings.

func Error

func Error(ctx context.Context, msg string)

Error log a error message.

func Errorf

func Errorf(ctx context.Context, template string, args ...any)

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

func Errorw(ctx context.Context, msg string, keysAndValues ...any)

Errorw logs a message with some additional context, With key and values, example: log.Errorw("message", "url", url, "attempt", 3) Keys in key-value pairs should be strings.

func Fatal

func Fatal(ctx context.Context, msg string)

Fatal log a fatal message.

func Fatalf

func Fatalf(ctx context.Context, template string, args ...any)

Fatalf uses fmt.Sprintf to log a templated message.

func Fatalw

func Fatalw(ctx context.Context, msg string, keysAndValues ...any)

Fatalw logs a message with some additional context, With key and values, example: log.Fatalw("message", "url", url, "attempt", 3) Keys in key-value pairs should be strings.

func Info

func Info(ctx context.Context, msg string)

Info log a info message.

func Infof

func Infof(ctx context.Context, template string, args ...any)

Infof uses fmt.Sprintf to log a templated message.

func Infow

func Infow(ctx context.Context, msg string, keysAndValues ...any)

Infow logs a message with some additional context, With key and values, example: log.Infow("message", "url", url, "attempt", 3) Keys in key-value pairs should be strings.

func NewLogger

func NewLogger(config Configuration) (err error)

NewLogger returns an instance of logger

func NoCTX added in v0.3.0

func NoCTX() *zapLogger

NoCTX allows access to log functions without the need to provide a context variable

func Panic

func Panic(ctx context.Context, msg string)

Panic log a panic message.

func Panicf

func Panicf(ctx context.Context, template string, args ...any)

Panicf uses fmt.Sprintf to log a templated message.

func Panicw

func Panicw(ctx context.Context, msg string, keysAndValues ...any)

Panicw logs a message with some additional context, With key and values, example: log.Panicw("message", "url", url, "attempt", 3) Keys in key-value pairs should be strings.

func Warn

func Warn(ctx context.Context, msg string)

Warn log a warn message.

func Warnf

func Warnf(ctx context.Context, template string, args ...any)

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

func Warnw(ctx context.Context, msg string, keysAndValues ...any)

Warnw logs a message with some additional context, With key and values, example: log.Warnw("message", "url", url, "attempt", 3) Keys in key-value pairs should be strings.

Types

type BaseFields

type BaseFields struct {
	ServiceName string
	Env         string
	CodeVersion string
}

BaseFields represents the base fields for create the basic fields of logger.

type Configuration

type Configuration struct {
	IsJSON     bool
	Level      string
	BaseFields BaseFields
	CTXFields  map[any]string
}

Configuration stores the config for the logger For some loggers there can only be one level across writers, for such the level of Console is picked by default

The CTXFields value maps the fields that the logger should look for in the context to its correspondent field in the logger. Ex.:

Configuration{
	CTXFields: map[any]string{
		0: "request_id"
	}
}

when loggin, will look for the value stored in the 0 key in the provided context, and log it on the "request_id" field, alongside the log message and information.

By default, if the CTX fields are specified or not, the lib will search for a request id in the context

Jump to

Keyboard shortcuts

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