Documentation
¶
Overview ¶
Package log is a standard logging system for IMQS Go applications.
This is a very thin wrapper around lumberjack. What this package provides is a consistent log format, with predefined severity levels.
Usage ¶
Create a new logger using log.New(filename, runtime.GOOS != "windows"). You can write to it using the various logging methods. 'filename' may also be log.Stdout or log.Stderr, in which case we do the obvious thing.
If you need to forward other log messages to this system, then Forwarder might have sufficient functionality to achieve that.
Index ¶
- Constants
- type Forwarder
- type Level
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(format string, params ...interface{})
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(format string, params ...interface{})
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(format string, params ...interface{})
- func (l *Logger) Log(level Level, msg string)
- func (l *Logger) Logf(level Level, format string, params ...interface{})
- func (l *Logger) Trace(msg string)
- func (l *Logger) Tracef(format string, params ...interface{})
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(format string, params ...interface{})
- func (l *Logger) Write(p []byte) (n int, err error)
Constants ¶
const ( Stdout = "stdout" Stderr = "stderr" Testing = ".testing." )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Forwarder ¶
type Forwarder struct { StripPrefixLen int // Number of bytes of prefix to strip (typically the timestamp from the incoming log message) Level Level // The log level assigned to all messages from this source Target *Logger // The destination }
Forwards log messages to an existing Logger, while performing some sanitizing which ensures that all log messages share the same format
func NewForwarder ¶
Create a new log forwarder
type Level ¶
type Level int
func ParseLevel ¶
Parse a level string such as "info" or "warn". Only the first character of the string is considered.
type Logger ¶
type Logger struct { Level Level // Log messages with a level lower than this are discarded. Default level is Info // contains filtered or unexported fields }
A logger object. Use New() to construct one.
var Log *Logger
This variable is initialized the first time New is called and then returned on every subsequent call. It can be used throughout an application by just importing this package into any package
func New ¶
New creates a new logger. If logToStdout is true all logs will be written to both the specified file and stdout. Filename may also be one of the special names log.Stdout and log.Stderr. If log.Stdout is specified and logToStdout is also set to true then the logs will only be written to stdout.
func NewTesting ¶
NewTesting creates a logger object that emits logs to the given Testing context