ServiceName: set the service name, optional. on
volumemode, the name is used to generate the log files. Within
rest/zrpcservices, the name will be set to the name of
Mode: the mode to output the logs, default is
consolemode writes the logs to
filemode writes the logs to the files specified by
volumemode is used in docker, to write logs into mounted volumes.
Encoding: indicates how to encode the logs, default is
jsonmode writes the logs in json format.
plainmode writes the logs with plain text, with terminal color enabled.
TimeFormat: customize the time format, optional. Default is
Path: set the log path, default to
Level: the logging level to filter logs. Default is
info, all logs are written.
infologs are suppressed.
errorlogs are suppressed, only
severelogs are written.
Compress: whether or not to compress log files, only works with
KeepDays: how many days that the log files are kept, after the given days, the outdated files will be deleted automatically. It has no effect on
StackCooldownMillis: how many milliseconds to rewrite stacktrace again. It’s used to avoid stacktrace flooding.
Slow: write any kind of messages into logs, with like
Slowf: write messages with given format into logs.
Slowv: write any kind of messages into logs, with json marshalling to encode them.
Sloww: write the string message with given
WithContext: inject the given ctx into the log messages, typically used to log
WithDuration: write elapsed duration into the log messages, with key
For more libs, please implement and PR to https://github.com/zeromicro/zero-contrib
logx defined two interfaces to let you customize
logx to write logs into any stores.
For example, if we want to write the logs into kafka instead of console or files, we can do it like below:
If we need to prevent the
password fields from logging, we can do it like below: