Documentation
¶
Overview ¶
import "github.com/xmlking/toolkit/logger" to `main.go` and all test files. set log level and format in via Env: CONFY_LOG_LEVEL, CONFY_LOG_FORMAT, CONFY_LOG_GRPC
Index ¶
- func FileWriter(filename string, c FileConfig) zerolog.LevelWriter
- func Init(options ...Option) error
- type FileConfig
- type Format
- type Logger
- type Option
- func EnableGrpcLog(val bool) Option
- func ReportCaller() Option
- func SetOption(k, v interface{}) Option
- func WithFields(fields map[string]interface{}) Option
- func WithFormat(format Format) Option
- func WithLevel(level zerolog.Level) Option
- func WithOutput(out io.Writer) Option
- func WithTimeFormat(timeFormat string) Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileWriter ¶ added in v0.5.1
func FileWriter(filename string, c FileConfig) zerolog.LevelWriter
Types ¶
type FileConfig ¶ added in v0.5.1
type FileConfig struct {
// MaxSize is the maximum size in megabytes of the log file before it gets
// rotated. It defaults to 100 megabytes.
MaxSize int
// MaxAge is the maximum number of days to retain old log files based on the
// timestamp encoded in their filename. Note that a day is defined as 24
// hours and may not exactly correspond to calendar days due to daylight
// savings, leap seconds, etc. The default is not to remove old log files
// based on age.
MaxAge int
// MaxBackups is the maximum number of old log files to retain. The default
// is to retain all old log files (though MaxAge may still cause them to get
// deleted.)
MaxBackups int
// LocalTime determines if the time used for formatting the timestamps in
// backup files is the computer's local time. The default is to use UTC
// time.
LocalTime bool
// Compress determines if the rotated log files should be compressed
// using gzip. The default is not to perform compression.
Compress bool
}
type Option ¶
type Option func(*Options)
func EnableGrpcLog ¶
func WithFields ¶
WithFields set default fields for the logger
func WithFormat ¶
WithFormat set default log format for the logger
func WithOutput ¶
WithOutput set default output writer for the logger
func WithTimeFormat ¶
WithTimeFormat set default timeFormat for the logger
type Options ¶
type Options struct {
// The logging level the logger should log at. default is `InfoLevel`
Level zerolog.Level
// Log format. default `json`
Format Format
// TimeFormat is one of time.RFC3339, time.RFC3339Nano, time.*
TimeFormat string
// Flag for whether to log caller info (off by default)
ReportCaller bool
// fields to always be logged
Fields map[string]interface{}
// It's common to set this to a file, or leave it default which is `os.Stderr`
Out io.Writer
// Enable/Disable GRPC Logs
EnableGrpcLog bool
// Alternative options
Context context.Context
}
Click to show internal directories.
Click to hide internal directories.