Documentation ¶
Overview ¶
Package for logging and sending logs to a log server, where they'll be aggregated into log objects and kept safe even if the client program exists or crashes.
Index ¶
- Constants
- Variables
- func Setup(appname, lvl string)
- func Shutdown()
- type Level
- func (l Level) Code() string
- func (l Level) Fatal(v ...interface{})
- func (l Level) Fatalf(format string, v ...interface{})
- func (l Level) Lower() string
- func (l Level) Print(v ...interface{})
- func (l Level) Printf(format string, v ...interface{})
- func (l Level) String() string
- func (l Level) Write(w []byte) (n int, err error)
- type Plog
- func (ctx *Plog) Close() error
- func (ctx *Plog) Log(key string, value interface{}) error
- func (ctx *Plog) LogAsString(key string, value []byte)
- func (ctx *Plog) LogDict(key string, kvs ...interface{}) error
- func (ctx *Plog) LogJSON(key string, value []byte)
- func (pctx *Plog) OpenDict(key string) *Plog
- func (pctx *Plog) OpenList(key string) *Plog
Constants ¶
const Crit = Critical
Variables ¶
var FallbackWriter io.Writer = os.Stderr
Where logs go if we can't connect to plogd. Defaults to stderr. Logs will be written prefixed with key and suffixed with a newline. All output is json encoded.
var LevelByName = map[string]Level{ "Emergency": Emergency, "EMERG": Emergency, "emerg": Emergency, "emergency": Emergency, "Alert": Alert, "ALERT": Alert, "alert": Alert, "Critical": Critical, "CRIT": Critical, "crit": Critical, "critical": Critical, "Error": Error, "ERR": Error, "err": Error, "error": Error, "Warning": Warning, "WARNING": Warning, "warning": Warning, "Notice": Notice, "NOTICE": Notice, "notice": Notice, "Info": Info, "INFO": Info, "info": Info, "Debug": Debug, "DEBUG": Debug, "debug": Debug, }
var LevelNames = map[Level]struct { Name, Code, Lower string }{ Emergency: {"Emergency", "EMERG", "emerg"}, Alert: {"Alert", "ALERT", "alert"}, Critical: {"Critical", "CRIT", "crit"}, Error: {"Error", "ERR", "err"}, Warning: {"Warning", "WARNING", "warning"}, Notice: {"Notice", "NOTICE", "notice"}, Info: {"Info", "INFO", "info"}, Debug: {"Debug", "DEBUG", "debug"}, }
var SetupLevel = Info
Threshold for logging, only this and higher prio levels will log.
Functions ¶
Types ¶
type Level ¶
type Level int
func LogLevel ¶
Returns the Level mathcing lvl, if it's valid, otherwise returns def. Commonly used with the lower case codes, either shortened or full.
func (Level) Code ¶
Upper-case code for level, matching logs. Levels Emergency to Error are shortened, while Warning to Debug are full name upper-case.
func (Level) Lower ¶
Lower-case code for level. Levels Emergency to Error are shortened, while Warning to Debug are full name lower-case.
func (Level) Print ¶
func (l Level) Print(v ...interface{})
Calls l.Write via fmt.Fprint. Checks l against the SetupLevel first and thus is slightly more efficient than calling fmt.Fprint directly.
type Plog ¶
type Plog struct {
// contains filtered or unexported fields
}
A plog context is an object opened in the log server. The server will keep track of it and all its contents until it's closed (and beyond, in case of state contexts). If a program crashes/exits without closing the context the server will detect this and log an "@interrupted" key for easier debugging.
var Default *Plog
Default plog context, opened by Setup.
func IfEnabled ¶
Returns the default context if the level is enabled by the threshold given to setup, otherwise nil. It's safe to call functions on nil contexts.
func NewPlogCount ¶
Open a new root count plog context. When integers are logged in this context, it's applied as a delta to the state. When the context is closed the integer values added are removed. Can be used to keep statistics such as number of open fds and aggregate them between multiple processes with the same name.
func NewPlogLog ¶
Open a new root logging plog context. If you called Setup, then you should probably use Default instead of this.
func NewPlogState ¶
Open a new root state plog context. State is kept in plogd and only logged with a "state" key once all state contexts for the appname are closed. You can also query it over HTTP from plogd.
func (*Plog) Close ¶
Close the context, marking it as properly closed in the server. For subcontext, this is what triggers it being sent to the parent context.
func (*Plog) Log ¶
Encode value as JSON and log it. Might return errors from json.Marshal, but that should only happen in very rare cases. For strings, ints and other basic types you can ignore the return value.
func (*Plog) LogAsString ¶
Log value as if it was a string.
func (*Plog) LogDict ¶
Log a JSON dictionary from the variadic arguments, alternating keys and values, key first. Note that the first argument is not part of the dictionary, it's the message key. Might return errors from json.Marshal.
func (*Plog) LogJSON ¶
Log raw JSON encoded data in value. You must make sure the JSON is valid, or the context will be aborted.