Documentation
¶
Overview ¶
Package flash configures an opinionated zap logger.
Index ¶
- type EncoderType
- type FileConfig
- type Logger
- type Option
- func WithColor() Option
- func WithDebug(debug bool) Option
- func WithEncoder(e EncoderType) Option
- func WithFile(cfg FileConfig) Option
- func WithPrometheus(appName string, registry prometheus.Registerer) Option
- func WithSinks(sinks ...string) Option
- func WithStacktrace() Option
- func WithoutCaller() Option
- func WithoutTimestamps() Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncoderType ¶ added in v0.3.0
type EncoderType int
EncoderType is a zap encoder.
const ( Console EncoderType = iota JSON LogFmt )
All supported encoder types.
type FileConfig ¶ added in v0.3.0
FileConfig holds the configuration for logging into a file. The size is in Megabytes and MaxAge is in days. If compress is true the rotated files are compressed.
type Logger ¶
type Logger struct { *zap.SugaredLogger // contains filtered or unexported fields }
Logger is the flash logger which embeds a `zap.SugaredLogger`.
func New ¶
New creates a new Logger. If no options are specified, stacktraces and color output are disabled and the confgured level is `InfoLevel`.
func (*Logger) Disable ¶
func (l *Logger) Disable()
Disable disables (nearly) all output. Only `FatalLevel` errors are logged.
type Option ¶
type Option func(c *config)
Option configures zap.Config.
func WithEncoder ¶ added in v0.3.0
func WithEncoder(e EncoderType) Option
WithEncoder configures the zap encoder.
func WithFile ¶ added in v0.3.0
func WithFile(cfg FileConfig) Option
WithFile configures the logger to log output into a file.
func WithPrometheus ¶
func WithPrometheus(appName string, registry prometheus.Registerer) Option
WithPrometheus registers a prometheus log message counter.
The created metrics are of the form:
<appName>_log_messages_total{level="info"} 4
If appName is an empty string `flash` is used.
func WithStacktrace ¶
func WithStacktrace() Option
WithStacktrace completely enables automatic stacktrace capturing. Stacktraces are captured on `ErrorLevel` and above when in debug mode. When not in debug mode, only `FatalLevel` messages contain stacktraces.
func WithoutCaller ¶
func WithoutCaller() Option
WithoutCaller stops annotating logs with the calling function's file name and line number.
func WithoutTimestamps ¶ added in v0.5.0
func WithoutTimestamps() Option
WithoutTimestamps configures the logger to log without timestamps.