Documentation ¶
Overview ¶
A simple logging module that mimics the behavior of Python's logging module.
All it does basically is wrap Go's logger with nice multi-level logging calls, and allows you to set the logging level of your app in runtime.
Logging is done just like calling fmt.Sprintf:
logging.Info("This object is %s and that is %s", obj, that)
example output:
2013/05/07 01:20:26 INFO @ db.go:528: Registering plugin REPLICATION 2013/05/07 01:20:26 INFO @ db.go:562: Registered 6 plugins and 22 commands 2013/05/07 01:20:26 INFO @ slave.go:277: Running replication watchdog loop! 2013/05/07 01:20:26 INFO @ redis.go:49: Redis adapter listening on 0.0.0.0:2000 2013/05/07 01:20:26 WARN @ main.go:69: Starting adapter... 2013/05/07 01:20:26 INFO @ db.go:966: Finished dump load. Loaded 2 objects from dump 2013/05/07 01:22:26 INFO @ db.go:329: Checking persistence... 0 changes since 2m0.000297531s 2013/05/07 01:22:26 INFO @ db.go:337: No need to save the db. no changes... 2013/05/07 01:22:26 DEBUG @ db.go:341: Sleeping for 2m0s
Index ¶
- Constants
- Variables
- func BridgeStdLog(level int)
- func Critical(msg string, args ...interface{})
- func Criticalf(msg string, args ...interface{}) error
- func Debug(msg string, args ...interface{})
- func Error(msg string, args ...interface{})
- func Errorf(msg string, args ...interface{}) error
- func Info(msg string, args ...interface{})
- func Notice(msg string, args ...interface{})
- func Panic(msg string, args ...interface{})
- func SetHandler(h LoggingHandler)
- func SetLevel(l int)
- func SetMinimalLevel(l int)
- func SetMinimalLevelByName(l string) error
- func SetOutput(w io.Writer)
- func Warning(msg string, args ...interface{})
- func Warningf(msg string, args ...interface{}) error
- type Formatter
- type LoggingHandler
- type MessageContext
- type SimpleFormatter
Constants ¶
const ( DEBUG = 1 INFO = 2 WARNING = 4 WARN = 4 ERROR = 8 NOTICE = 16 //notice is like info but for really important stuff ;) CRITICAL = 32 QUIET = ERROR | NOTICE | CRITICAL //setting for errors only NORMAL = INFO | WARN | ERROR | NOTICE | CRITICAL // default setting - all besides debug ALL = 255 NOTHING = 0 )
Variables ¶
Functions ¶
func BridgeStdLog ¶
func BridgeStdLog(level int)
BridgeStdLog bridges all messages written using the standard library's log.Print* and makes them output through this logger, at a given level.
func Critical ¶
func Critical(msg string, args ...interface{})
Output a CRITICAL level message while showing a stack trace
func Criticalf ¶
Same as critical but also returns an error object with the message regardless of logging level
func Errorf ¶
Same as Error() but also returns a new formatted error object with the message regardless of logging level
func Panic ¶
func Panic(msg string, args ...interface{})
Raise a PANIC while writing the stack trace to the log
func SetHandler ¶
func SetHandler(h LoggingHandler)
Set the current handler of the library. We currently support one handler, but it might be nice to have more
func SetLevel ¶
func SetLevel(l int)
Set the logging level.
Contrary to Python that specifies a minimal level, this logger is set with a bit mask of active levels.
e.g. for INFO and ERROR use:
SetLevel(logging.INFO | logging.ERROR)
For everything but debug and info use:
SetLevel(logging.ALL &^ (logging.INFO | logging.DEBUG))
func SetMinimalLevel ¶
func SetMinimalLevel(l int)
Set a minimal level for loggin, setting all levels higher than this level as well.
the severity order is DEBUG, INFO, WARNING, ERROR, CRITICAL
func SetMinimalLevelByName ¶
Set minimal level by string, useful for config files and command line arguments. Case insensitive.
Possible level names are DEBUG, INFO, WARNING, ERROR, NOTICE, CRITICAL
Types ¶
type Formatter ¶
type Formatter interface {
Format(ctx *MessageContext, message string, args ...interface{}) string
}
A formatting interface- it is responsible of taking the arguments and composing a message
var DefaultFormatter Formatter = &SimpleFormatter{
FormatString: "[%[1]s %[2]s, %[3]s:%[4]d] %[5]s",
}
type LoggingHandler ¶
type LoggingHandler interface { SetFormatter(Formatter) Emit(ctx *MessageContext, message string, args ...interface{}) error }
a pluggable logger interface
func CurrentHandler ¶
func CurrentHandler() LoggingHandler
type MessageContext ¶
type SimpleFormatter ¶
type SimpleFormatter struct {
FormatString string
}
func (*SimpleFormatter) Format ¶
func (f *SimpleFormatter) Format(ctx *MessageContext, message string, args ...interface{}) string