Documentation ¶
Index ¶
- Constants
- Variables
- func DisableZap()
- func EnableZap()
- func GloballyDisableDebugLogForTest()
- func GloballyEnableDebugLogForTest()
- func InitGlobalLogger(logger *Logger)
- func NewLogrTarget(name string, t *LogTarget) (logr.Target, error)
- func RedirectStdLog(logger *Logger)
- type AddTargetFunc
- type ConfigFunc
- type EnableMetricsFunc
- type Field
- type FlushFunc
- type LogFunc
- type LogFuncCustom
- type LogFuncCustomMulti
- type LogLevel
- type LogTarget
- type LogTargetCfg
- type Logger
- func (l *Logger) AddTarget(targets ...logr.Target) error
- func (l *Logger) ChangeLevels(config *LoggerConfiguration)
- func (l *Logger) ConfigAdvancedLogging(targets LogTargetCfg) error
- func (l *Logger) Critical(message string, fields ...Field)
- func (l *Logger) Debug(message string, fields ...Field)
- func (l *Logger) EnableMetrics(collector logr.MetricsCollector) error
- func (l *Logger) Error(message string, fields ...Field)
- func (l *Logger) Flush(cxt context.Context) error
- func (l *Logger) Info(message string, fields ...Field)
- func (l *Logger) Log(level LogLevel, message string, fields ...Field)
- func (l *Logger) LogM(levels []LogLevel, message string, fields ...Field)
- func (l *Logger) RemoveTargets(ctx context.Context, f func(ti TargetInfo) bool) error
- func (l *Logger) SetConsoleLevel(level string)
- func (l *Logger) ShutdownAdvancedLogging(cxt context.Context) error
- func (l *Logger) StdLog(fields ...Field) *log.Logger
- func (l *Logger) StdLogAt(level string, fields ...Field) (*log.Logger, error)
- func (l *Logger) StdLogWriter() io.Writer
- func (l *Logger) Sugar() *SugarLogger
- func (l *Logger) Warn(message string, fields ...Field)
- func (l *Logger) With(fields ...Field) *Logger
- func (l *Logger) WithCallerSkip(skip int) *Logger
- type LoggerConfiguration
- type LogrCleanup
- type RemoveTargetsFunc
- type ShutdownFunc
- type SugarLogger
- type Syslog
- type SyslogParams
- type TargetInfo
- type Tcp
- type TcpParams
Constants ¶
const ( // Very verbose messages for debugging specific issues LevelDebug = "debug" // Default log level, informational LevelInfo = "info" // Warnings are messages about possible issues LevelWarn = "warn" // Errors are messages about things we know are problems LevelError = "error" // DefaultFlushTimeout is the default amount of time mlog.Flush will wait // before timing out. DefaultFlushTimeout = time.Second * 5 )
const ( DefaultMaxTargetQueue = 1000 DefaultSysLogPort = 514 )
const ( DialTimeoutSecs = 30 WriteTimeoutSecs = 30 RetryBackoffMillis int64 = 100 MaxRetryBackoffMillis int64 = 30 * 1000 // 30 seconds )
Variables ¶
var ( LvlPanic = LogLevel{ID: 0, Name: "panic", Stacktrace: true} LvlFatal = LogLevel{ID: 1, Name: "fatal", Stacktrace: true} LvlError = LogLevel{ID: 2, Name: "error"} LvlWarn = LogLevel{ID: 3, Name: "warn"} LvlInfo = LogLevel{ID: 4, Name: "info"} LvlDebug = LogLevel{ID: 5, Name: "debug"} LvlTrace = LogLevel{ID: 6, Name: "trace"} // used by redirected standard logger LvlStdLog = LogLevel{ID: 10, Name: "stdlog"} // used only by the logger LvlLogError = LogLevel{ID: 11, Name: "logerror", Stacktrace: true} )
Standard levels
var ( // used by the audit system LvlAuditAPI = LogLevel{ID: 100, Name: "audit-api"} LvlAuditContent = LogLevel{ID: 101, Name: "audit-content"} LvlAuditPerms = LogLevel{ID: 102, Name: "audit-permissions"} LvlAuditCLI = LogLevel{ID: 103, Name: "audit-cli"} // used by the TCP log target LvlTcpLogTarget = LogLevel{ID: 120, Name: "TcpLogTarget"} )
Register custom (discrete) levels here. !!!!! ID's must not exceed 32,768 !!!!!!
var Any = zap.Any
var Bool = zap.Bool
var Duration = zap.Duration
var Err = zap.Error
var Int = zap.Int
var Int32 = zap.Int32
var Int64 = zap.Int64
var (
MLvlAuditAll = []LogLevel{LvlAuditAPI, LvlAuditContent, LvlAuditPerms, LvlAuditCLI}
)
Combinations for LogM (log multi)
var NamedErr = zap.NamedError
var String = zap.String
var Uint32 = zap.Uint32
Functions ¶
func DisableZap ¶
func DisableZap()
DisableZap is called to disable Zap, and Logr will be used instead. Any Logger instances created after this call will only use Logr.
This is needed for unit testing as Zap has no shutdown capabilities and holds file handles until process exit. Currently unit tests create many server instances, and thus many Zap log file handles.
This method will be removed when Zap is permanently replaced.
func EnableZap ¶
func EnableZap()
EnableZap re-enables Zap such that any Logger instances created after this call will allow Zap targets.
func GloballyDisableDebugLogForTest ¶
func GloballyDisableDebugLogForTest()
DON'T USE THIS Modify the level on the app logger
func GloballyEnableDebugLogForTest ¶
func GloballyEnableDebugLogForTest()
DON'T USE THIS Modify the level on the app logger
func InitGlobalLogger ¶
func InitGlobalLogger(logger *Logger)
func NewLogrTarget ¶
NewLogrTarget creates a `logr.Target` based on a target config. Can be used when parsing custom config files, or when programmatically adding built-in targets. Use `mlog.AddTarget` to add custom targets.
func RedirectStdLog ¶
func RedirectStdLog(logger *Logger)
Types ¶
type AddTargetFunc ¶
var AddTarget AddTargetFunc = defaultAddTarget
type ConfigFunc ¶
type ConfigFunc func(cfg LogTargetCfg) error
var ConfigAdvancedLogging ConfigFunc = defaultAdvancedConfig
type EnableMetricsFunc ¶
type EnableMetricsFunc func(logr.MetricsCollector) error
var EnableMetrics EnableMetricsFunc = defaultEnableMetrics
type LogFunc ¶
var Critical LogFunc = defaultCriticalLog
var Debug LogFunc = defaultDebugLog
var Error LogFunc = defaultErrorLog
var Info LogFunc = defaultInfoLog
var Warn LogFunc = defaultWarnLog
type LogFuncCustom ¶
var Log LogFuncCustom = defaultCustomLog
type LogFuncCustomMulti ¶
var LogM LogFuncCustomMulti = defaultCustomMultiLog
type LogTargetCfg ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger ¶
func NewLogger(config *LoggerConfiguration) *Logger
func NewTestingLogger ¶
NewTestingLogger creates a Logger that proxies logs through a testing interface. This allows tests that spin up App instances to avoid spewing logs unless the test fails or -verbose is specified.
func (*Logger) AddTarget ¶
AddTarget adds one or more logr.Target to the advanced logger. This is the preferred method to add custom targets or provide configuration that cannot be expressed via a config source.
func (*Logger) ChangeLevels ¶
func (l *Logger) ChangeLevels(config *LoggerConfiguration)
func (*Logger) ConfigAdvancedLogging ¶
func (l *Logger) ConfigAdvancedLogging(targets LogTargetCfg) error
ConfigAdvancedLoggingConfig (re)configures advanced logging based on the specified log targets. This is the easiest way to get the advanced logger configured via a config source such as file.
func (*Logger) EnableMetrics ¶
func (l *Logger) EnableMetrics(collector logr.MetricsCollector) error
EnableMetrics enables metrics collection by supplying a MetricsCollector. The MetricsCollector provides counters and gauges that are updated by log targets.
func (*Logger) RemoveTargets ¶
RemoveTargets selectively removes targets that were previously added to this logger instance using the passed in filter function. The filter function should return true to remove the target and false to keep it.
func (*Logger) SetConsoleLevel ¶
func (*Logger) ShutdownAdvancedLogging ¶
ShutdownAdvancedLogging stops the logger from accepting new log records and tries to flush queues within the context timeout. Once complete all targets are shutdown and any resources released.
func (*Logger) StdLogAt ¶
StdLogAt returns *log.Logger which writes to supplied zap logger at required level.
func (*Logger) StdLogWriter ¶
StdLogWriter returns a writer that can be hooked up to the output of a golang standard logger anything written will be interpreted as log entries accordingly
func (*Logger) Sugar ¶
func (l *Logger) Sugar() *SugarLogger
Made for the plugin interface, wraps mlog in a simpler interface at the cost of performance
func (*Logger) WithCallerSkip ¶
type LoggerConfiguration ¶
type LogrCleanup ¶
type LogrCleanup func() error
type RemoveTargetsFunc ¶
type RemoveTargetsFunc func(context.Context, func(TargetInfo) bool) error
var RemoveTargets RemoveTargetsFunc = defaultRemoveTargets
type ShutdownFunc ¶
var ShutdownAdvancedLogging ShutdownFunc = defaultAdvancedShutdown
type SugarLogger ¶
type SugarLogger struct {
// contains filtered or unexported fields
}
Made for the plugin interface, use the regular logger for other uses
func (*SugarLogger) Debug ¶
func (l *SugarLogger) Debug(msg string, keyValuePairs ...interface{})
func (*SugarLogger) Error ¶
func (l *SugarLogger) Error(msg string, keyValuePairs ...interface{})
func (*SugarLogger) Info ¶
func (l *SugarLogger) Info(msg string, keyValuePairs ...interface{})
func (*SugarLogger) Warn ¶
func (l *SugarLogger) Warn(msg string, keyValuePairs ...interface{})
type Syslog ¶
Syslog outputs log records to local or remote syslog.
func NewSyslogTarget ¶
func NewSyslogTarget(filter logr.Filter, formatter logr.Formatter, params *SyslogParams, maxQueue int) (*Syslog, error)
NewSyslogTarget creates a target capable of outputting log records to remote or local syslog, with or without TLS.
func (*Syslog) Shutdown ¶
Shutdown stops processing log records after making best effort to flush queue.
type SyslogParams ¶
type SyslogParams struct { IP string `json:"IP"` Port int `json:"Port"` Tag string `json:"Tag"` TLS bool `json:"TLS"` Cert string `json:"Cert"` Insecure bool `json:"Insecure"` }
SyslogParams provides parameters for dialing a syslog daemon.
type TargetInfo ¶
type TargetInfo logr.TargetInfo
type Tcp ¶
Tcp outputs log records to raw socket server.
func NewTcpTarget ¶
func NewTcpTarget(filter logr.Filter, formatter logr.Formatter, params *TcpParams, maxQueue int) (*Tcp, error)
NewTcpTarget creates a target capable of outputting log records to a raw socket, with or without TLS.
func (*Tcp) Shutdown ¶
Shutdown stops processing log records after making best effort to flush queue.