Documentation ¶
Overview ¶
Package log provides infrastructure for topic based logging to files.
Currently all loggers must be specified through the Initialize call and each may be accessed through package's Get. Before program termination Close should be called to gracefully flush all loggers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{ Filename: "", TeeTo: os.Stderr, Flags: log.LstdFlags | log.Lshortfile, Prefix: "", }
DefaultConfig provides some reasonable defaults for topic config.
Failsafe is used to prevent dataloss in the case where a log client attempts to access a log before it has been initialized.
Functions ¶
func Close ¶
func Close()
Close will Close on all files that have been opened for logging.
Accessing a topic-specific logger via Get after closing them will cause output to be logged to stderr instead of the desired file but will not panic.
Log entries that were previously logging to files will also have a [closed] prefix added to indicate their underlying Writer has been closed and changed.
Signals for logrotation will no longer be observed.
func Get ¶
Get provides access to a configured logger. If a logger for the requested topic has not been configured return Failsafe and log the issue.
NOTE: use of Get will acquire a read lock on the state mutex. This by itself isn't problematic but when we are handling a SIGHUP we also acquire a lock while we reopen log files. If Get usage is going to be frequent spend some time to minimize that critical section.
func Initialize ¶
func Initialize( stdoutOnly bool, logRoot string, rotateOnSignal bool, topicConfig map[string]Config, fileOpenErrCB func(string, io.WriteCloser, error) io.WriteCloser, ) error
Initialize confgures logging and individual topic based loggers.
Parameters: stdoutOnly - all loggers will ignore file destinations and produce output to stdout. Their topic will be prefixed to the log line logRoot - indicates the path directory all log files should be placed in rotateOnSignal - if set to true this package will listen for SIGHUP signals and reopen the log file they're writing to when it is received; has no meaning if stdoutOnly is set topicConfig - maps topic to logger config. fileOpenErrCB - in the event a file fails to open during rotation or initialization this will be called; it will be passed the topic, the previous file pointer, and the error from opening the file. If a new file pointer is returned that will be used as the location logging continues.
If Initialize is called twice it will return an error.
If fileOpenErrCB is nil the default behavior is to set the logger's output to Stderr, log the error, and continue operating.
func LogAndPanic ¶
func LogAndPanic(topic string, prev io.WriteCloser, err error) io.WriteCloser
LogAndPanic is a default handler that just logs the error and panics instead of trying to recover or continue.
Types ¶
type Config ¶
type Config struct { // Filename indicates the name of the log file that entries should be sent to. Filename string // If TeeTo is set entries will also be sent to the indicated Writer. TeeTo io.Writer // golang log.Logger flags Flags int // log line prefix Prefix string }
Config specifies how a particular logger should operate.