Documentation
¶
Overview ¶
Package log is a logging library focused on performance. Unlike other logging libraries all log messages
are functions that generate their log messages. Log messages are required to be wrapped into functions to avoid the issues that occur where log statements are of a lower level than the current log level. Typically log statement are written for _, item := range largeSliceOfSomething { log.Info("Processing: %s", item.String()) } String() is allocating a string. If the log level is set to Error, the info statement is never written to the log file. Instead if we wrap the construction of the log message into a function, we only call String when it is needed.
Index ¶
- Constants
- func Error(key Key, builderFunc BuildingFunction, args ...interface{})
- func Fatal(key Key, builderFunc BuildingFunction, args ...interface{})
- func Info(key Key, builderFunc BuildingFunction, args ...interface{})
- func RegisterLogger(logger *Logger)
- func StringBuilder(args ...interface{}) string
- func Warn(key Key, builderFunc BuildingFunction, args ...interface{})
- type Backend
- type BuildingFunction
- type CircularBuffer
- type DateFormat
- type Key
- type Level
- type Logger
- type WriterBackend
Constants ¶
const ( ANSIC = "Mon Jan _2 15:04:05 2006" UnixDate = "Mon Jan _2 15:04:05 MST 2006" RubyDate = "Mon Jan 02 15:04:05 -0700 2006" RFC822 = "02 Jan 06 15:04 MST" RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone RFC850 = "Monday, 02-Jan-06 15:04:05 MST" RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST" RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone RFC3339 = "2006-01-02T15:04:05Z07:00" RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" Kitchen = "3:04PM" // Handy time stamps. Stamp = "Jan _2 15:04:05" StampMilli = "Jan _2 15:04:05.000" StampMicro = "Jan _2 15:04:05.000000" StampNano = "Jan _2 15:04:05.000000000" )
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(key Key, builderFunc BuildingFunction, args ...interface{})
Error emits a log message at the info level to its backend. Not safe to use with other go-routines that add or remove loggers. Depending on the backend used, might not be safe to use with any go-routine. Check the details of the backend for whether it is safe to use in any go routine.
If the logger is set at error level or higher the logging function will be called with the arguments, otherwise the function is not called. Any work that is to be done in building the log message is intended to be contained within the logging function, with the arguments raw values used in the calling code.
func Fatal ¶
func Fatal(key Key, builderFunc BuildingFunction, args ...interface{})
Fatal emits a log message at the info level to its backend. Not safe to use with other go-routines that add or remove loggers. Depending on the backend used, might not be safe to use with any go-routine. Check the details of the backend for whether it is safe to use in any go routine.
If the logger is set at fatal level or higher the logging function will be called with the arguments, otherwise the function is not called. Any work that is to be done in building the log message is intended to be contained within the logging function, with the arguments raw values used in the calling code.
func Info ¶
func Info(key Key, builderFunc BuildingFunction, args ...interface{})
Info emits a log message at the info level to its backend. Not safe to use with other go-routines that add or remove loggers. Depending on the backend used, might not be safe to use with any go-routine. Check the details of the backend for whether it is safe to use in any go routine.
If the logger is set at info level or higher the logging function will be called with the arguments, otherwise the function is not called. Any work that is to be done in building the log message is intended to be contained within the logging function, with the arguments raw values used in the calling code.
func RegisterLogger ¶
func RegisterLogger(logger *Logger)
Register accepts a Logger so that later it can be used.
func Warn ¶
func Warn(key Key, builderFunc BuildingFunction, args ...interface{})
Warn emits a log message at the info level to its backend. Not safe to use with other go-routines that add or remove loggers. Depending on the backend used, might not be safe to use with any go-routine. Check the details of the backend for whether it is safe to use in any go routine.
If the logger is set at warn level or higher the logging function will be called with the arguments, otherwise the function is not called. Any work that is to be done in building the log message is intended to be contained within the logging function, with the arguments raw values used in the calling code.
Types ¶
type Backend ¶
type Backend interface { // Write composes a log message using the level, message, and the particular logger that generated the message // to a particular destination. Write(level Level, msg string, logger *Logger) }
Backend is the low level code that writes out a log message to a particular source (e.g. stdout, file...etc).
type BuildingFunction ¶
type BuildingFunction func(args ...interface{}) string
BuildingFunction is the function use to construct the log message.
type CircularBuffer ¶
type CircularBuffer struct {
// contains filtered or unexported fields
}
func NewCircularBuffer ¶
func NewCircularBuffer(size int) *CircularBuffer
func (*CircularBuffer) Append ¶
func (buffer *CircularBuffer) Append(data []byte) error
type DateFormat ¶
type DateFormat string
DateFormat is the type used for defining formats for dates.
const ( // YYYYMMDDHHMMSS is a DateFormat that produced dates in Year.Month.Day.Hour.Minute.Second format. // e.g. 1984.11.04.10.20:05 YYYYMMDDHHMMSS DateFormat = "2006.01.02.15:04:05" SmallMessageSize = 4096 )
type Level ¶
type Level int8
Level is the log level of a particular logger.
const ( // DEBUG is the lowest level of logging for developer use. DEBUG Level = 1 // INFO is the log level used for logging informative non-debug information. INFO Level = 2 // WARN is the log level used to log messages that are potentially problems. WARN Level = 3 // ERROR is the log level used to log messages that are recoverable errors. ERROR Level = 4 // CRITICAL is the log level used to log messages that are nearly fatal, but leave the system still in a usable // state CRITICAL Level = 5 // FATAL is the log level used to log a message before destructively killing the system. FATAL Level = 6 )
type Logger ¶
type Logger struct { Key Key Description string Enabled bool Level Level Backend Backend TimeFormat DateFormat }
Logger contains the state of a particular logger.
type WriterBackend ¶
type WriterBackend struct {
// contains filtered or unexported fields
}
WriterBackend is a backend that sends all log message output to a writer.
func NewFileBackend ¶
func NewFileBackend(file *os.File) *WriterBackend
NewFileBackend creates a backend that writes to a file. The file must already have been opened and ready for writing. Closing the file is the responsibility of the caller.
func NewStdoutBackend ¶
func NewStdoutBackend() *WriterBackend
NewStdoutBackend creates a backend that only writes to standard out.
func NewWriterBackend ¶
func NewWriterBackend(writer io.Writer) *WriterBackend
NewWriterBackend creates a backend that sends all log messages to the provided writer.
func (*WriterBackend) Write ¶
func (backend *WriterBackend) Write(level Level, msg string, logger *Logger)