Documentation ¶
Overview ¶
Package rlog provides a partial reimplementation of the log package in the standard library. This package provides simple logging with loglevels and an interface quite similar to the standard library. The following environment variables are supported:
GO_RLOG_LEVEL GO_RLOG_JOURNAL
In addition to the SetLogLevel() methods, the loglevel can be set globally via an environment variable. The recognized values are: CRIT, ERR, WARN, NOTICE, INFO, and DEBUG. These constants are defined in RFC5435, Section 6.2.1.
For your convenience, there is a package level logger available, which can be accessed using the relevant methods. The package level logger is there for programs that do not need several loggers. It aims to simplify this particular usecase. If you need several loggers, please instantiate them as needed and do not use the package level logger.
Timestamps are not supported by design, since this is almost always not needed. On the terminal, you can pipe the output through ts(1) from moreutils. Using a logging service, the timestamps are already handled perfectly. This avoids the annoying problem of doubled timestamps in the log database, such as: Aug 10 07:24:37 host service[pid]: TIMESTAMP MESSAGE.
Index ¶
- Constants
- Variables
- func Crit(v ...interface{})
- func Critf(format string, v ...interface{})
- func Critln(v ...interface{})
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func EnableJournalPrio(enabled bool)
- func EnableLines(calldepth int)
- func EnablePrefix(enabled bool)
- func EnableStacktrace(enabled bool)
- func Err(v ...interface{})
- func Errf(format string, v ...interface{})
- func Errln(v ...interface{})
- func GetLogLevel() int
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Infoln(v ...interface{})
- func Notice(v ...interface{})
- func Noticef(format string, v ...interface{})
- func Noticeln(v ...interface{})
- func SetLogLevel(logLevel int)
- func SetModule(module string)
- func SetWriter(writer io.Writer)
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- func Warningln(v ...interface{})
- type Logger
- func (l *Logger) Crit(v ...interface{})
- func (l *Logger) Critf(format string, v ...interface{})
- func (l *Logger) Critln(v ...interface{})
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) EnableJournalPrio(enabled bool)
- func (l *Logger) EnableLines(calldepth int)
- func (l *Logger) EnablePrefix(enabled bool)
- func (l *Logger) EnableStacktrace(enabled bool)
- func (l *Logger) Err(v ...interface{})
- func (l *Logger) Errf(format string, v ...interface{})
- func (l *Logger) Errln(v ...interface{})
- func (l *Logger) GetLogLevel() int
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) Notice(v ...interface{})
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) Noticeln(v ...interface{})
- func (l *Logger) SetLogLevel(logLevel int)
- func (l *Logger) SetModule(module string)
- func (l *Logger) SetWriter(writer io.Writer)
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- func (l *Logger) Warningln(v ...interface{})
Constants ¶
const ( EMERG = iota ALERT CRIT ERR WARNING NOTICE INFO DEBUG )
RFC5424 Section 6.2.1
Variables ¶
var DefaultLogLevel = INFO
DefaultLogLevel holds the default loglevel of this package. It is exported in order to be overwritable at compile time by -ldflags="-X ...".
Functions ¶
func Crit ¶
func Crit(v ...interface{})
Crit is the same as Crit, but for the package level default logger.
func Critf ¶
func Critf(format string, v ...interface{})
Critf is the same as Critf, but for the package level default logger.
func Critln ¶
func Critln(v ...interface{})
Critln is the same as Critln, but for the package level default logger.
func Debug ¶
func Debug(v ...interface{})
Debug is the same as Debug, but for the package level default logger.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf is the same as Debugf, but for the package level default logger.
func Debugln ¶
func Debugln(v ...interface{})
Debugln is the same as Debugln, but for the package level default logger.
func EnableJournalPrio ¶
func EnableJournalPrio(enabled bool)
EnableJournalPrio is the same as EnableJournalPrio, but for the package level default logger.
func EnableLines ¶
func EnableLines(calldepth int)
EnableLines is the same as EnableLines, but for the package level default logger.
func EnablePrefix ¶
func EnablePrefix(enabled bool)
EnablePrefix is the same as EnablePrefix, but for the package level default logger.
func EnableStacktrace ¶
func EnableStacktrace(enabled bool)
EnableStacktrace is the same as EnableLines, but for the package level default logger.
func Err ¶
func Err(v ...interface{})
Err is the same as Err, but for the package level default logger.
func Errf ¶
func Errf(format string, v ...interface{})
Errf is the same as Errf, but for the package level default logger.
func Errln ¶
func Errln(v ...interface{})
Errln is the same as Errln, but for the package level default logger.
func GetLogLevel ¶
func GetLogLevel() int
GetLogLevel is the same as GetLogLevel, but for the package level default logger.
func Info ¶
func Info(v ...interface{})
Info is the same as Info, but for the package level default logger.
func Infof ¶
func Infof(format string, v ...interface{})
Infof is the same as Infof, but for the package level default logger.
func Infoln ¶
func Infoln(v ...interface{})
Infoln is the same as Infoln, but for the package level default logger.
func Notice ¶
func Notice(v ...interface{})
Notice is the same as Notice, but for the package level default logger.
func Noticef ¶
func Noticef(format string, v ...interface{})
Noticef is the same as Noticef, but for the package level default logger.
func Noticeln ¶
func Noticeln(v ...interface{})
Noticeln is the same as Noticeln, but for the package level default logger.
func SetLogLevel ¶
func SetLogLevel(logLevel int)
SetLogLevel is the same as SetLogLevel, but for the package level default logger.
func SetModule ¶
func SetModule(module string)
SetModule is the same as SetModule, but for the package level default logger.
func Warning ¶
func Warning(v ...interface{})
Warning is the same as Warning, but for the package level default logger.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the handle to be used for emitting logmessages. Do not instantiate it manually, use NewLogger().
func NewLogger ¶
NewLogger creates a fresh instance if Logger. The environment variable GO_RLOG_LEVEL is checked whether it is equal to the strings EMERG, ALERT, CRIT, ERR, WARNING, INFO, DEBUG. In this case, the loglevel of the returned Logger is set accordingly. Otherwise, DefaultLogLevel is used. Logger by default logs to stderr.
func (*Logger) Crit ¶
func (l *Logger) Crit(v ...interface{})
Crit logs a message and terminates the program with exit code 1.
func (*Logger) Critf ¶
Critf logs a message and terminates the program with exit code 1. It accepts a Printf style format string.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug logs a message with priority debug. A newline is appended.
func (*Logger) Debugf ¶
Debugf logs a message wit priority debug. It accepts a Printf style format string.
func (*Logger) EnableJournalPrio ¶
EnableJournalPrio enables priority prefixes like <1>. If logging to systemd-journal(8), the priority is parsed and stored along the message.
func (*Logger) EnableLines ¶
EnableLines enables file names and line numbers in the log output.
func (*Logger) EnablePrefix ¶
EnablePrefix enables or disables the logging prefix, for instance "[d]".
func (*Logger) EnableStacktrace ¶
EnableStacktrace enables printing a stacktrace for ERR and CRIT messages.
func (*Logger) Err ¶
func (l *Logger) Err(v ...interface{})
Err logs a message with loglevel err. A newline is appended.
func (*Logger) Errf ¶
Errf logs a message wit loglevel err. It accepts a Printf style format string.
func (*Logger) GetLogLevel ¶
GetLogLevel retrieves the loglevel from the logger.
func (*Logger) Info ¶
func (l *Logger) Info(v ...interface{})
Info logs a message with priority info. A newline is appended.
func (*Logger) Infof ¶
Infof logs a message wit priority info. It accepts a Printf style format string.
func (*Logger) Notice ¶
func (l *Logger) Notice(v ...interface{})
Notice logs a message with priority notice. A newline is appended.
func (*Logger) Noticef ¶
Noticef logs a message wit priority notice. It accepts a Printf style format string.
func (*Logger) Noticeln ¶
func (l *Logger) Noticeln(v ...interface{})
Noticeln is the same as Notice.
func (*Logger) SetLogLevel ¶
SetLogLevel sets the loglevel of the logger. Please use the exported constants to set the loglevel accordingly.
func (*Logger) Warning ¶
func (l *Logger) Warning(v ...interface{})
Warning logs a message with priority warning. A newline is appended.