log

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// EnvironmentProduction production log environment.
	EnvironmentProduction = LogEnvironment("production")
	// EnvironmentDevelopment development log environment.
	EnvironmentDevelopment = LogEnvironment("development")
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug calls log.Debug on the root Logger.

func Debugf

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

Debugf calls log.Debugf on the root Logger.

func Debugw

func Debugw(msg string, kv ...interface{})

Debugw calls log.Debugw on the root Logger.

func Error

func Error(args ...interface{})

Error calls log.Error on the root Logger.

func Errorf

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

Errorf calls log.Errorf on the root logger and stores the error message into the ErrorFile.

func Errorw

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

Errorw calls log.Errorw on the root Logger.

func Fatal

func Fatal(args ...interface{})

Fatal calls log.Fatal on the root Logger.

func Fatalf

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

Fatalf calls log.Fatalf on the root Logger.

func Fatalw

func Fatalw(msg string, kv ...interface{})

Fatalw calls log.Fatalw on the root Logger.

func Info

func Info(args ...interface{})

Info calls log.Info on the root Logger.

func Infof

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

Infof calls log.Infof on the root Logger.

func Infow

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

Infow calls log.Infow on the root Logger.

func Init

func Init(cfg Config)

Init the logger with defined level. outputs defines the outputs where the logs will be sent. By default outputs contains "stdout", which prints the logs at the output of the process. To add a log file as output, the path should be added at the outputs array. To avoid printing the logs but storing them on a file, can use []string{"pathtofile.log"}

func NewLogger

func NewLogger(cfg Config) (*zap.SugaredLogger, *zap.AtomicLevel, error)

NewLogger creates the logger with defined level. outputs defines the outputs where the logs will be sent. By default, outputs contains "stdout", which prints the logs at the output of the process. To add a log file as output, the path should be added at the outputs array. To avoid printing the logs but storing them on a file, can use []string{"pathtofile.log"}

func Warn

func Warn(args ...interface{})

Warn calls log.Warn on the root Logger.

func Warnf

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

Warnf calls log.Warnf on the root Logger.

func Warnw

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

Warnw calls log.Warnw on the root Logger.

Types

type Config

type Config struct {
	// Environment defining the log format ("production" or "development").
	// In development mode, the logger:
	// - Enables development settings (e.g., DPanicLevel logs panic)
	// - Uses a console encoder and writes to standard error
	// - Disables sampling
	// - Automatically includes stack traces on WarnLevel and above
	// Check [here](https://pkg.go.dev/go.uber.org/zap@v1.24.0#NewDevelopmentConfig)
	Environment LogEnvironment `mapstructure:"Environment" jsonschema:"enum=production,enum=development"`
	// Level of log. As lower value more logs are going to be generated
	Level string `mapstructure:"Level" jsonschema:"enum=debug,enum=info,enum=warn,enum=error,enum=dpanic,enum=panic,enum=fatal"` //nolint:lll
	// Outputs
	Outputs []string `mapstructure:"Outputs"`
}

Config for log

type LogEnvironment

type LogEnvironment string

LogEnvironment represents the possible log environments.

type Logger

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

Logger is a wrapper providing logging facilities.

func WithFields

func WithFields(keyValuePairs ...interface{}) *Logger

WithFields returns a new Logger (derived from the root one) with additional fields as per keyValuePairs. The root Logger instance is not affected.

func (*Logger) Debug

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

Debug calls log.Debug

func (*Logger) Debugf

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

Debugf calls log.Debugf

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, kv ...interface{})

Debugw calls log.Debugw

func (*Logger) Error

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

Error calls log.Error

func (*Logger) Errorf

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

Errorf calls log.Errorf and stores the error message into the ErrorFile

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, kv ...interface{})

Errorw calls log.Errorw

func (*Logger) Fatal

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

Fatal calls log.Fatal

func (*Logger) Fatalf

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

Fatalf calls log.Fatalf

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, kv ...interface{})

Fatalw calls log.Fatalw

func (*Logger) Info

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

Info calls log.Info

func (*Logger) Infof

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

Infof calls log.Infof

func (*Logger) Infow

func (l *Logger) Infow(msg string, kv ...interface{})

Infow calls log.Infow

func (*Logger) Warn

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

Warn calls log.Warn

func (*Logger) Warnf

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

Warnf calls log.Warnf

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, kv ...interface{})

Warnw calls log.Warnw

func (*Logger) WithFields

func (l *Logger) WithFields(keyValuePairs ...interface{}) *Logger

WithFields returns a new Logger with additional fields as per keyValuePairs. The original Logger instance is not affected.

Jump to

Keyboard shortcuts

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