Documentation ¶
Overview ¶
picolog is a tiny levelled logging package for go. It supports syslog log levels, subloggers, and not much else. Written because all the existing solutions either didn't do what I needed or were too weighty.
Example ¶
package main import ( "fmt" "github.com/anchor/picolog" "os" ) func main() { level, err := picolog.ParseLogLevel("info") if err != nil { fmt.Printf("This can't happen: %v", err) } // Log messages will be prefixed by "[example]" and a timestamp. logger := picolog.NewLogger(level, "example", os.Stdout) logger.Infof("Printing a log message!") logger.Debugf("Not printing this message at INFO log level.") }
Output:
Index ¶
- Constants
- type LogLevel
- type Logger
- func (l *Logger) Alertf(format string, v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Emergf(format string, v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) NewSubLogger(prefix string) *Logger
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) Printf(format string, level LogLevel, v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
Examples ¶
Constants ¶
const ( LogDebug LogLevel = LogLevel(syslog.LOG_DEBUG) LogInfo = LogLevel(syslog.LOG_INFO) LogNotice = LogLevel(syslog.LOG_NOTICE) LogWarning = LogLevel(syslog.LOG_WARNING) LogErr = LogLevel(syslog.LOG_ERR) LogCrit = LogLevel(syslog.LOG_CRIT) LogAlert = LogLevel(syslog.LOG_ALERT) LogEmerg = LogLevel(syslog.LOG_EMERG) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogLevel ¶
LogLevel is a type representing the usual syslog log levels from LOG_DEBUG to LOG_EMERG. It does not reflect the go syslog package's concept of 'Priority'.
func ParseLogLevel ¶
ParseLogLevel takes a string and returns a LogLevel according to the standard syslog string representation. Not case-sensitive.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a leveled logger type. It can be a sublogger of another logger, and have an arbitrary number of subloggers itself.
func NewDefaultLogger ¶
func NewDefaultLogger() *Logger
NewDefaultLogger returns a picolog.Logger initialized with workable defaults (outputs to stderr, prefix "default", priority DEBUG). Useful as a fallback when a logger hasn't been initialized.
func NewLogger ¶
Return a new Logger. logLevel is a syslog log level, subpackage is used to construct the log prefix, and dest is where to write the log to.
func (*Logger) Fatalf ¶
Fatalf logs one printf-formatted message at LOG_CRIT, and then exits with an error code.
func (*Logger) NewSubLogger ¶
NewSubLogger returns a Logger writing to the same stream, with a prefix constructed from the provided prefix and the parent Logger's prefix. Subloggers can be nested.