logger

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDevConfig = LoggerConfig{
	Environment:  "dev",
	Folder:       "logs",
	Filename:     "app.log",
	Encoder:      "console",
	LogToConsole: true,
	Level:        -int(zap.DebugLevel),
	MaxSizeInMB:  500,
	MaxAge:       90,
	Compress:     true,
}

default configuration for dev environment

View Source
var DefaultPrdConfig = LoggerConfig{
	Environment:  "prod",
	Folder:       "logs",
	Filename:     "app.log",
	Encoder:      "json",
	LogToConsole: true,
	Level:        2,
	MaxSizeInMB:  100,
	MaxAge:       10,
	Compress:     true,
}

default configuration for production environment

Functions

func InitLogger

func InitLogger(cf *LoggerConfig)

InitLogger initializes the logger based on running mode

func NewLogger

func NewLogger(cf LoggerConfig) *zap.Logger

Types

type LoggerConfig

type LoggerConfig struct {
	// The logging environment, "prod" for production and any other value for "development"
	Environment string `yaml:"environment"`
	// The encoder for logs, "json" and any other value for "console"
	Encoder string `yaml:"encoder"`
	// Folder is the log folder
	Folder string `yaml:"folder"`
	// Filename is the name of the log file
	Filename string `yaml:"filename"`
	// Should be also write the log to the console
	LogToConsole bool `yaml:"logToConsole"`
	// the bigger, the less important logs to user (for example, INFO=0, DEBUG=1,...)
	// if the level set to K, the app outputs only the messages are logged with level <= K
	Level int `yaml:"level"`
	// max size of each log file before rolling
	MaxSizeInMB int `yaml:"maxSizeInMB"`
	// number of backups
	MaxBackups int `yaml:"maxBackups"`
	// compress the log file
	Compress bool `yaml:"compress"`
	// max age of a log file
	MaxAge int `yaml:"maxAge"`
	// should we skip logging the caller and the line number
	SkipCaller bool `yaml:"skipCaller"`
}

LoggerConfig contains all configuration

Jump to

Keyboard shortcuts

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