Documentation ¶
Index ¶
- func NewToggledLogger(underlying hclog.Logger, enabled *atomic.Bool) hclog.Logger
- type ToggledLogger
- func (tl *ToggledLogger) Debug(msg string, args ...any)
- func (tl *ToggledLogger) Error(msg string, args ...any)
- func (tl *ToggledLogger) GetLevel() hclog.Level
- func (tl *ToggledLogger) ImpliedArgs() []any
- func (tl *ToggledLogger) Info(msg string, args ...any)
- func (tl *ToggledLogger) IsDebug() bool
- func (tl *ToggledLogger) IsError() bool
- func (tl *ToggledLogger) IsInfo() bool
- func (tl *ToggledLogger) IsTrace() bool
- func (tl *ToggledLogger) IsWarn() bool
- func (tl *ToggledLogger) Log(level hclog.Level, msg string, args ...any)
- func (tl *ToggledLogger) Name() string
- func (tl *ToggledLogger) Named(name string) hclog.Logger
- func (tl *ToggledLogger) ResetNamed(name string) hclog.Logger
- func (tl *ToggledLogger) SetEnabled(enabled bool)
- func (tl *ToggledLogger) SetLevel(level hclog.Level)
- func (tl *ToggledLogger) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger
- func (tl *ToggledLogger) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer
- func (tl *ToggledLogger) Trace(msg string, args ...any)
- func (tl *ToggledLogger) Warn(msg string, args ...any)
- func (tl *ToggledLogger) With(args ...any) hclog.Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewToggledLogger ¶
NewToggledLogger creates a new logger, without performing nil checking on the underlying logger.
If enabled is provided, it is used when checking whether to log, which can be useful for tying lifecycle of enablement of this logger to some other process. If nil, an internal value will be created and used.
Types ¶
type ToggledLogger ¶
type ToggledLogger struct {
// contains filtered or unexported fields
}
ToggledLogger is used to provide an hclog-compatible interface that can be turned on/off at will. This is useful for providing a logger where you only want logging to happen in specific debugging scenarios. The enabled flag is an atomic bool; a common pattern with this library will be to read a config value at SIGHUP and set the bool to the currently desired value.
When using With and Named and such, the returned logger will share the enabled state of this logger. If this is not what you want, create a new ToggledLogger with the result of With or Name directly called on the underlying logger.
func (*ToggledLogger) Debug ¶
func (tl *ToggledLogger) Debug(msg string, args ...any)
Debug logs a message at the Debug level, if this logger is enabled
func (*ToggledLogger) Error ¶
func (tl *ToggledLogger) Error(msg string, args ...any)
Error logs a message at the Error level, if this logger is enabled
func (*ToggledLogger) GetLevel ¶
func (tl *ToggledLogger) GetLevel() hclog.Level
GetLevel returns the current level
func (*ToggledLogger) ImpliedArgs ¶
func (tl *ToggledLogger) ImpliedArgs() []any
ImpliedArgs returns the implied args of the underlying logger
func (*ToggledLogger) Info ¶
func (tl *ToggledLogger) Info(msg string, args ...any)
Info logs a message at the Info level, if this logger is enabled
func (*ToggledLogger) IsDebug ¶
func (tl *ToggledLogger) IsDebug() bool
IsDebug returns the call of the same name on the underlying logger
func (*ToggledLogger) IsError ¶
func (tl *ToggledLogger) IsError() bool
IsError returns the call of the same name on the underlying logger
func (*ToggledLogger) IsInfo ¶
func (tl *ToggledLogger) IsInfo() bool
IsInfo returns the call of the same name on the underlying logger
func (*ToggledLogger) IsTrace ¶
func (tl *ToggledLogger) IsTrace() bool
IsTrace returns the call of the same name on the underlying logger
func (*ToggledLogger) IsWarn ¶
func (tl *ToggledLogger) IsWarn() bool
IsWarn returns the call of the same name on the underlying logger
func (*ToggledLogger) Log ¶
func (tl *ToggledLogger) Log(level hclog.Level, msg string, args ...any)
Log logs a message at the given level, if this logger is enabled
func (*ToggledLogger) Name ¶
func (tl *ToggledLogger) Name() string
func (*ToggledLogger) Named ¶
func (tl *ToggledLogger) Named(name string) hclog.Logger
Named returns the underlying logger with Named called, but shares this logger's enabled state
func (*ToggledLogger) ResetNamed ¶
func (tl *ToggledLogger) ResetNamed(name string) hclog.Logger
ResetNamed returns the underlying logger with ResetNamed called, but shares this logger's enabled state
func (*ToggledLogger) SetEnabled ¶
func (tl *ToggledLogger) SetEnabled(enabled bool)
SetEnabled sets the enabled state of the logger
func (*ToggledLogger) SetLevel ¶
func (tl *ToggledLogger) SetLevel(level hclog.Level)
SetLevel sets the level of the underlying logger
func (*ToggledLogger) StandardLogger ¶
func (tl *ToggledLogger) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger
StandardLogger is currently not supported and returns nil
func (*ToggledLogger) StandardWriter ¶
func (tl *ToggledLogger) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer
StandardWriter is currently not supported and returns nil
func (*ToggledLogger) Trace ¶
func (tl *ToggledLogger) Trace(msg string, args ...any)
Trace logs a message at the Trace level, if this logger is enabled
func (*ToggledLogger) Warn ¶
func (tl *ToggledLogger) Warn(msg string, args ...any)
Warn logs a message at the Warn level, if this logger is enabled
func (*ToggledLogger) With ¶
func (tl *ToggledLogger) With(args ...any) hclog.Logger
With returns the underlying logger with With called, but shares this logger's enabled state