log

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 7 Imported by: 13

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

View Source
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
)
View Source
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

func NowString

func NowString() string

NowString returns a very detailed time string.

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.

func (*Event) Fmt

func (e *Event) Fmt(f string) string

Fmt creates a log event string from the provided format. Use Event.String() to look it up again without reparsing.

type LogShortcuts added in v0.4.0

type LogShortcuts struct {
	// Logger structure.
	Logger *Logger
	// L logs to stdout by default.
	L func(string, ...interface{})
	// E logs to stderr by default.
	E func(string, ...interface{})
}

LogShortcuts for the lazy. Embed these for convenience.

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) Err

func (l *Logger) Err(f string, v ...interface{})

Err prints arbitrary formatted errors to the configured error output(s).

func (*Logger) Fail added in v0.3.0

func (l *Logger) Fail(err error, t bool)

Fail is meant to be deferred with closing operations which might return an error. If t is true, the output will be timestamped with the default format of the logger. Any error returns 2 to the operating system, which is considered a major error.

func (*Logger) Log

func (l *Logger) Log(e *Event)

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) Msg

func (l *Logger) Msg(f string, v ...interface{})

Msg prints arbitrary formatted messages to the configured message output(s).

func (*Logger) Printf added in v0.4.0

func (l *Logger) Printf(f string, v ...interface{})

Printf wraps Msg for compatibility with some other loggers.

func (*Logger) SetELogFmt

func (l *Logger) SetELogFmt(s string)

SetELogFmt sets the output format for error event logs.

func (*Logger) SetFmt

func (l *Logger) SetFmt(s string)

SetFmt for messages and errors to the same format.

func (*Logger) SetLogFmt

func (l *Logger) SetLogFmt(s string)

SetLogFmt sets the output format for informational event logs.

func (*Logger) SetLogOut

func (l *Logger) SetLogOut(log byte, files, servers []string)

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.

func (*Logger) TErr

func (l *Logger) TErr(f string, v ...interface{})

TErr prints arbitrary formatted errors to the configured error output(s), starting with a timestamp.

func (*Logger) TMsg

func (l *Logger) TMsg(f string, v ...interface{})

TMsg prints arbitrary formatted messages to the configured message output(s), starting with a timestamp.

func (*Logger) Warn added in v0.3.0

func (l *Logger) Warn(err error, t bool)

Warn is meant to be deferred with closing operations which might return an error. If t is true, the output will be timestamped with the default format of the logger. Any error returns 1 to the operating system, which is considered a warning/minor error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL