mlog

package
v5.3.2-0...-ccc9e37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2020 License: AGPL-3.0, Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	DefaultMaxTargetQueue = 1000
	DefaultSysLogPort     = 514
)
View Source
const (
	DialTimeoutSecs             = 30
	WriteTimeoutSecs            = 30
	RetryBackoffMillis    int64 = 100
	MaxRetryBackoffMillis int64 = 30 * 1000 // 30 seconds
)

Variables

View Source
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

View Source
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 !!!!!!

View Source
var Any = zap.Any
View Source
var Bool = zap.Bool
View Source
var Duration = zap.Duration
View Source
var Err = zap.Error
View Source
var Int = zap.Int
View Source
var Int32 = zap.Int32
View Source
var Int64 = zap.Int64

Combinations for LogM (log multi)

View Source
var NamedErr = zap.NamedError
View Source
var String = zap.String
View Source
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

func NewLogrTarget(name string, t *LogTarget) (logr.Target, error)

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

type AddTargetFunc func(...logr.Target) error
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 Field

type Field = zapcore.Field

Type and function aliases from zap to limit the libraries scope into MM code

type FlushFunc

type FlushFunc func(context.Context) error
var Flush FlushFunc = defaultFlush

type LogFunc

type LogFunc func(string, ...Field)
var Critical LogFunc = defaultCriticalLog
var Debug LogFunc = defaultDebugLog
var Error LogFunc = defaultErrorLog
var Info LogFunc = defaultInfoLog
var Warn LogFunc = defaultWarnLog

type LogFuncCustom

type LogFuncCustom func(LogLevel, string, ...Field)
var Log LogFuncCustom = defaultCustomLog

type LogFuncCustomMulti

type LogFuncCustomMulti func([]LogLevel, string, ...Field)
var LogM LogFuncCustomMulti = defaultCustomMultiLog

type LogLevel

type LogLevel struct {
	ID         logr.LevelID
	Name       string
	Stacktrace bool
}

type LogTarget

type LogTarget struct {
	Type         string // one of "console", "file", "tcp", "syslog", "none".
	Format       string // one of "json", "plain"
	Levels       []LogLevel
	Options      json.RawMessage
	MaxQueueSize int
}

type LogTargetCfg

type LogTargetCfg map[string]*LogTarget

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(config *LoggerConfiguration) *Logger

func NewTestingLogger

func NewTestingLogger(tb testing.TB, writer io.Writer) *Logger

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

func (l *Logger) AddTarget(targets ...logr.Target) error

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) Critical

func (l *Logger) Critical(message string, fields ...Field)

func (*Logger) Debug

func (l *Logger) Debug(message string, fields ...Field)

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) Error

func (l *Logger) Error(message string, fields ...Field)

func (*Logger) Flush

func (l *Logger) Flush(cxt context.Context) error

func (*Logger) Info

func (l *Logger) Info(message string, fields ...Field)

func (*Logger) Log

func (l *Logger) Log(level LogLevel, message string, fields ...Field)

func (*Logger) LogM

func (l *Logger) LogM(levels []LogLevel, message string, fields ...Field)

func (*Logger) RemoveTargets

func (l *Logger) RemoveTargets(ctx context.Context, f func(ti TargetInfo) bool) error

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 (l *Logger) SetConsoleLevel(level string)

func (*Logger) ShutdownAdvancedLogging

func (l *Logger) ShutdownAdvancedLogging(cxt context.Context) error

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) StdLog

func (l *Logger) StdLog(fields ...Field) *log.Logger

func (*Logger) StdLogAt

func (l *Logger) StdLogAt(level string, fields ...Field) (*log.Logger, error)

StdLogAt returns *log.Logger which writes to supplied zap logger at required level.

func (*Logger) StdLogWriter

func (l *Logger) StdLogWriter() io.Writer

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) Warn

func (l *Logger) Warn(message string, fields ...Field)

func (*Logger) With

func (l *Logger) With(fields ...Field) *Logger

func (*Logger) WithCallerSkip

func (l *Logger) WithCallerSkip(skip int) *Logger

type LoggerConfiguration

type LoggerConfiguration struct {
	EnableConsole bool
	ConsoleJson   bool
	ConsoleLevel  string
	EnableFile    bool
	FileJson      bool
	FileLevel     string
	FileLocation  string
}

type LogrCleanup

type LogrCleanup func() error

type RemoveTargetsFunc

type RemoveTargetsFunc func(context.Context, func(TargetInfo) bool) error
var RemoveTargets RemoveTargetsFunc = defaultRemoveTargets

type ShutdownFunc

type ShutdownFunc func(context.Context) error
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

type Syslog struct {
	logr.Basic
	// contains filtered or unexported fields
}

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

func (s *Syslog) Shutdown(ctx context.Context) error

Shutdown stops processing log records after making best effort to flush queue.

func (*Syslog) String

func (s *Syslog) String() string

String returns a string representation of this target.

func (*Syslog) Write

func (s *Syslog) Write(rec *logr.LogRec) error

Write converts the log record to bytes, via the Formatter, and outputs to syslog.

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

type Tcp struct {
	logr.Basic
	// contains filtered or unexported fields
}

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

func (tcp *Tcp) Shutdown(ctx context.Context) error

Shutdown stops processing log records after making best effort to flush queue.

func (*Tcp) String

func (tcp *Tcp) String() string

String returns a string representation of this target.

func (*Tcp) Write

func (tcp *Tcp) Write(rec *logr.LogRec) error

Write converts the log record to bytes, via the Formatter, and outputs to the socket. Called by dedicated target goroutine and will block until success or shutdown.

type TcpParams

type TcpParams struct {
	IP       string `json:"IP"`
	Port     int    `json:"Port"`
	TLS      bool   `json:"TLS"`
	Cert     string `json:"Cert"`
	Insecure bool   `json:"Insecure"`
}

TcpParams provides parameters for dialing a socket server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL