Documentation ¶
Overview ¶
Package logs defines an interface and default implementation for subsystem logging.
Log level verbosity may be modified at runtime for each individual subsystem logger.
The default implementation in this package must be created by the Backend type. Backends can write to any io.Writer, including multi-writers created by io.MultiWriter. Multi-writers allow log output to be written to many writers, including standard output and log files.
Optional logging behavior can be specified by using the LOGFLAGS environment variable and overridden per-Backend by using the WithFlags call option. Multiple LOGFLAGS options can be specified, separated by commas. The following options are recognized:
longfile: Include the full filepath and line number in all log messages shortfile: Include the filename and line number in all log messages. Overrides longfile.
Index ¶
- Constants
- type Backend
- type BackendOption
- type Level
- type Logger
- func (l *Logger) Backend() *Backend
- func (l *Logger) Critical(args ...interface{})
- func (l *Logger) Criticalf(format string, args ...interface{})
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Level() Level
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Trace(args ...interface{})
- func (l *Logger) Tracef(format string, args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) Write(logLevel Level, args ...interface{})
- func (l *Logger) Writef(logLevel Level, format string, args ...interface{})
Constants ¶
const ( // Llongfile modifies the logger output to include full path and line number // of the logging callsite, e.g. /a/b/c/main.go:123. Llongfile uint32 = 1 << iota // Lshortfile modifies the logger output to include filename and line number // of the logging callsite, e.g. main.go:123. Overrides Llongfile. Lshortfile )
Flags to modify Backend's behavior.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a logging backend. Subsystems created from the backend write to the backend's Writer. Backend provides atomic writes to the Writer from all subsystems.
func NewBackend ¶
func NewBackend(opts ...BackendOption) *Backend
NewBackend creates a new logger backend.
func (*Backend) AddLogFile ¶
AddLogFile adds a file which the log will write into on a certain log level with the default log rotation settings. It'll create the file if it doesn't exist.
func (*Backend) AddLogFileWithCustomRotator ¶
func (b *Backend) AddLogFileWithCustomRotator(logFile string, logLevel Level, thresholdKB int64, maxRolls int) error
AddLogFileWithCustomRotator adds a file which the log will write into on a certain log level, with the specified log rotation settings. It'll create the file if it doesn't exist.
type BackendOption ¶
type BackendOption func(b *Backend)
BackendOption is a function used to modify the behavior of a Backend.
func WithFlags ¶
func WithFlags(flags uint32) BackendOption
WithFlags configures a Backend to use the specified flags rather than using the package's defaults as determined through the LOGFLAGS environment variable.
type Level ¶
type Level uint32
Level is the level at which a logger is configured. All messages sent to a level which is below the current level are filtered.
Level constants.
func LevelFromString ¶
LevelFromString returns a level based on the input string s. If the input can't be interpreted as a valid log level, the info level and false is returned.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a subsystem logger for a Backend.
func (*Logger) Critical ¶
func (l *Logger) Critical(args ...interface{})
Critical formats message using the default formats for its operands, prepends the prefix as necessary, and writes to log with LevelCritical.
func (*Logger) Criticalf ¶
Criticalf formats message according to format specifier, prepends the prefix as necessary, and writes to log with LevelCritical.
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug formats message using the default formats for its operands, prepends the prefix as necessary, and writes to log with LevelDebug.
func (*Logger) Debugf ¶
Debugf formats message according to format specifier, prepends the prefix as necessary, and writes to log with LevelDebug.
func (*Logger) Error ¶
func (l *Logger) Error(args ...interface{})
Error formats message using the default formats for its operands, prepends the prefix as necessary, and writes to log with LevelError.
func (*Logger) Errorf ¶
Errorf formats message according to format specifier, prepends the prefix as necessary, and writes to log with LevelError.
func (*Logger) Info ¶
func (l *Logger) Info(args ...interface{})
Info formats message using the default formats for its operands, prepends the prefix as necessary, and writes to log with LevelInfo.
func (*Logger) Infof ¶
Infof formats message according to format specifier, prepends the prefix as necessary, and writes to log with LevelInfo.
func (*Logger) Trace ¶
func (l *Logger) Trace(args ...interface{})
Trace formats message using the default formats for its operands, prepends the prefix as necessary, and writes to log with LevelTrace.
func (*Logger) Tracef ¶
Tracef formats message according to format specifier, prepends the prefix as necessary, and writes to log with LevelTrace.
func (*Logger) Warn ¶
func (l *Logger) Warn(args ...interface{})
Warn formats message using the default formats for its operands, prepends the prefix as necessary, and writes to log with LevelWarn.
func (*Logger) Warnf ¶
Warnf formats message according to format specifier, prepends the prefix as necessary, and writes to log with LevelWarn.