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:
[DBG 1670353253256778 instance.go:123] Setting config: projects [DBG 1670353253259897 subshell.go:95] Detected SHELL: zsh [DBG 1670353253259915 subshell.go:132] Using binary: /bin/zsh
Index ¶
- Constants
- Variables
- func BridgeStdLog(level int)
- func Close()
- func Critical(msg string, args ...interface{})
- func Debug(msg string, args ...interface{})
- func Error(msg string, args ...interface{})
- func ErrorNoStacktrace(msg string, args ...interface{})
- func FileName() string
- func FileNameFor(pid int) string
- func FileNameForCmd(cmd string, pid int) string
- func FileNamePrefix() string
- func FilePath() string
- func FilePathFor(filename string) string
- func FilePathForCmd(cmd string, pid int) string
- func Info(msg string, args ...interface{})
- func Notice(msg string, args ...interface{})
- func Panic(msg string, args ...interface{})
- func ReadTail() string
- func SetHandler(h LoggingHandler)
- func SetLevel(l int)
- func SetMinimalLevel(l int)
- func SetMinimalLevelByName(l string) error
- func SetOutput(w io.Writer)
- func StartRotateLogTimer() func()
- func Warning(msg string, args ...interface{})
- type Formatter
- type Logger
- 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 )
const FileNameSuffix = ".log"
const TailSize = 5000
TailSize specifies the number of logged bytes to keep for use with Tail.
Variables ¶
var LevelsByName = map[string]int{ "DEBUG": DEBUG, "INFO": INFO, "WARNING": WARN, "WARN": WARN, "ERROR": ERROR, "NOTICE": NOTICE, "CRITICAL": CRITICAL, "QUIET": QUIET, "NORMAL": NORMAL, "ALL": ALL, "NOTHING": NOTHING, }
var LogPrefixRx = regexp.MustCompile(`^[a-zA-Z\-]+`)
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 This should be called sparingly, as multilog.Critical() is preferred.
func Error ¶
func Error(msg string, args ...interface{})
Output ERROR level messages This should be used sparingly, as multilog.Error() is preferred.
func ErrorNoStacktrace ¶
func ErrorNoStacktrace(msg string, args ...interface{})
Same as Error() but without a stacktrace.
func FileNameFor ¶
func FileNameForCmd ¶
func FileNamePrefix ¶
func FileNamePrefix() string
func FilePathFor ¶
func FilePathForCmd ¶
func Panic ¶
func Panic(msg string, args ...interface{})
Raise a PANIC while writing the stack trace to the log
func ReadTail ¶
func ReadTail() string
ReadTail returns as a string the last TailSize bytes written by this logger.
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
func StartRotateLogTimer ¶
func StartRotateLogTimer() func()
StartRotateLogTimer starts log rotation on a timer and returns a function that should be called to stop it.
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 Logger ¶
type Logger func(msg string, args ...interface{})
Logger describes a logging function, like Debug, Error, Warning, etc.
type LoggingHandler ¶
type LoggingHandler interface { SetFormatter(Formatter) SetVerbose(bool) Output() io.Writer Emit(ctx *MessageContext, message string, args ...interface{}) error Printf(msg string, args ...interface{}) Close() }
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