Documentation ¶
Overview ¶
Package log contains the Logger, a complex (and possibly complicated) structure for logging of data from a longer-running process to different destinations. TODO: Define exactly what to do with JSON and RPC output.
Index ¶
- Constants
- func NowString() string
- type Event
- type Logger
- func (l *Logger) CloseFiles()
- func (l *Logger) Err(f string, v ...interface{})
- func (l *Logger) Log(e *Event)
- func (l *Logger) Msg(f string, v ...interface{})
- func (l *Logger) SetELogFmt(s string)
- func (l *Logger) SetFmt(s string)
- func (l *Logger) SetLogFmt(s string)
- func (l *Logger) SetLogOut(log byte, files, servers []string)
- func (l *Logger) TErr(f string, v ...interface{})
- func (l *Logger) TMsg(f string, v ...interface{})
Constants ¶
const ( // O_FILE for stdout+stderr or a filename. O_FILE = 1 // O_JSON for a JSON log server. O_JSON = 2 // O_RPC for a gRPC server. O_RPC = 4 )
const (
// DetailedFormat is the default log format which uses only the most essential fields.
DetailedFormat = "%host %time: Level %level crisis from %name on %src: %msg"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct { strings.Builder // Level of seriousness. App-specific, but generally 0 = informational, // and higher numbers increase criticality. Level uint `json:"level,omitempty"` // PID is a process identifier, if relevant. PID int `json:"pid,omitempty"` // Time is the timestamp of the event. Time time.Time `json:"timestamp,omitempty"` // Name of app or sub-system where event started. Name string `json:"name,omitempty"` // Hostname of the system the event originated from. Hostname string `json:"hostname,omitempty"` // Source is app-specific. Source string `json:"source,omitempty"` // Message is the human-readable form of the event message. Message string `json:"message,omitempty"` // Extra strings for whatever. Extra []string `json:"extra,omitempty"` }
Event line in a log file. Status, warnings, failures etc.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger structure for configurable output.
var Default *Logger
Default Logger object.
func NewLogger ¶
func NewLogger() *Logger
NewLogger creates a logger with some reasonable defaults for printing to stdout/stderr.
func (*Logger) CloseFiles ¶
func (l *Logger) CloseFiles()
CloseFiles closes any open non-stdout/stderr files and replaces them with stdout.
func (*Logger) Log ¶
Log an event to an appropriate output in a configured format for that log level. Level 0 defaults to stdout, anything else to stderr.
func (*Logger) SetELogFmt ¶
SetELogFmt sets the output format for error event logs.
func (*Logger) SetLogOut ¶
SetLogOut sets the output methods for messages and errors. files - filenames, or blank for stdout and stderr servers - host:port strings for remote logging destinations Specify O_FILE and blank files to use stdout and stderr. This can be combined with either O_JSON or O_RPC.