Documentation
¶
Overview ¶
Taken from https://github.com/psapezhka/hclog-zerolog/blob/main/wrapper.go
Index ¶
- Constants
- func Setup(cfg Config, output io.Writer) zerolog.Logger
- type Config
- type Logger
- func (l *Logger) Debug(format string, args ...any)
- func (l *Logger) Error(format string, args ...any)
- func (l *Logger) GetLevel() hclog.Level
- func (l *Logger) ImpliedArgs() []any
- func (l *Logger) Info(format string, args ...any)
- func (l *Logger) IsDebug() bool
- func (l *Logger) IsError() bool
- func (l *Logger) IsInfo() bool
- func (l *Logger) IsTrace() bool
- func (l *Logger) IsWarn() bool
- func (l *Logger) Log(level hclog.Level, msg string, args ...any)
- func (l *Logger) Name() string
- func (l *Logger) Named(name string) hclog.Logger
- func (l *Logger) ResetNamed(name string) hclog.Logger
- func (l *Logger) SetLevel(level hclog.Level)
- func (l *Logger) StandardLogger(_ *hclog.StandardLoggerOptions) *log.Logger
- func (l *Logger) StandardWriter(_ *hclog.StandardLoggerOptions) io.Writer
- func (l *Logger) Trace(format string, args ...any)
- func (l *Logger) Warn(format string, args ...any)
- func (l *Logger) With(args ...any) hclog.Logger
- type ZerologWriter
Constants ¶
const DefaultNameField = "hclog_name"
DefaultNameField — field hclog.Logger name will be written to.
hclog has a concept of logger name and, moreover, name inheritance (when you create named logger on top of named logger). Logger name acts like a prefix for the log message. On the other hand, zerolog operates key/value pairs to add context to messages. So, we convert the hclog logger name to key/value context pair for zerolog This is a default, can be overridden while creating wrapper with the NewWithCustomNameField
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewHCLogWrapper ¶
New creates an instance of Logger wrapping provided zerolog.Logger.
Example of wrapping the default global zerolog logger (using hashicorp/raft as an example of lib depending on hclog.Logger)
raftLogger := log.With().Str("component", "raft").Logger()
config := raft.DefaultConfig()
config.Logger = hclogzerolog.New(raftLogger)
See:
func NewWithCustomNameField ¶
NewWithCustomNameField — does exactly the same as [New] but with the ability to set field (key) the hclog.Logger name will be written to.
func (*Logger) ImpliedArgs ¶
func (*Logger) StandardLogger ¶
func (l *Logger) StandardLogger(_ *hclog.StandardLoggerOptions) *log.Logger
func (*Logger) StandardWriter ¶
func (l *Logger) StandardWriter(_ *hclog.StandardLoggerOptions) io.Writer
type ZerologWriter ¶
type ZerologWriter struct {
// contains filtered or unexported fields
}
ZerologWriter adapts zerolog to io.Writer for standard library log
func NewZeroLogWriter ¶
func NewZeroLogWriter(logger zerolog.Logger) *ZerologWriter