logger

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(cfg *config.Log)

InitLogger initializes the logger.

Example
_stderr := os.Stderr
os.Stderr = os.Stdout

location, _ := time.LoadLocation("UTC")
time.Local = location

zerolog.TimestampFunc = func() time.Time {
	return time.Unix(0, 0).UTC()
}

// Test log format

// empty format should log console
InitLogger(&config.Log{Format: ""})
log.Info().Msg("test empty")

// common format should log console
InitLogger(&config.Log{Format: "common"})
log.Info().Msg("test common")

// json format should log json
InitLogger(&config.Log{Format: "json"})
log.Info().Msg("test json")

// Test log level

// info level should not log debug
InitLogger(&config.Log{Level: "info"})
log.Info().Msg("test level info")
log.Debug().Msg("test level info -- ignored")

// debug level should add caller
InitLogger(&config.Log{Level: "debug"})
log.Info().Msg("test level debug")
Output:

1970-01-01T00:00:00Z INF test empty
1970-01-01T00:00:00Z INF test common
{"level":"info","time":"1970-01-01T00:00:00Z","message":"test json"}
1970-01-01T00:00:00Z INF test level info
1970-01-01T00:00:00Z INF logger_test.go:87 > test level debug

Types

This section is empty.

Jump to

Keyboard shortcuts

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