There are so many logging frameworks, it's not necessary to write a new one.
This package only provides some logging abstraction. The purpose is to be used as a middleware between business codes and other logging frameworks.
The Logger
interface has two methods:
Log()
: writes a log message.LogFn()
: similar toLog
, but accepts a factory function to produce the log message.
There are two built-in loggers:
NopLogger
: an empty logger that logs nothing.StdLogger
: writes logs to the standard output.
For more details, see the GoDoc.
The LoggerOp
struct provides a group of shortcut methods to simplify the usage of Logger
, such as Debug()
, Infof()
, Warnkv()
.
For more details, see the GoDoc.
LogManager
is used for managing Logger
s. It's safe for concurrent use.
Methods:
Set(name, Logger)
: register a logger with the given name into theLogManager
instance.Find(name)
: get a logger with the given name.Delete(name)
: deleted a registered logger from the instance.Op()
: similar toFind()
, but returns aLoggerOp
instance.
LogManager
uses case-insensitive header matching when finding Loggers. A name will be split by the dot(.) into several segments, when finding a name like 'A.B.C.D', LogManager
finds the Logger
in this order, returns the first found Logger
:
- a.b.c.d
- a.b.c
- a.b
- a
- "" (empty string)
If no logger can be found, LogManger.Find()
returns nil
.
The logger with the empty name is the root logger. The empty string can be treated as the first segment of all other names, e.g. The name 'a.b' is equivalent to '.a.b'.
It's similar to the
LoaManager
class inlog4j
fromJava
/Common.Logging
from.net
For more details, see the Example.