Documentation ¶
Index ¶
- Variables
- func Escape(b []byte) string
- func RoundDuration(d, to time.Duration) string
- func SiMultiple(n, multipleOf uint64, maxUnit byte) string
- type Composer
- type Level
- type Logger
- func (l *Logger) AddPeriodic(id string, minInterval, maxInterval time.Duration, f loggerFunc)
- func (l *Logger) Close()
- func (l *Logger) Compose(level Level) Composer
- func (l *Logger) Debug(format string, args ...interface{})
- func (l *Logger) Error(format string, args ...interface{})
- func (l *Logger) Fatal(format string, args ...interface{})
- func (l *Logger) FatalIf(cond bool, format string, args ...interface{})
- func (l *Logger) FatalIfErr(err error, format string, args ...interface{})
- func (l *Logger) Info(format string, args ...interface{})
- func (l *Logger) Log(level Level, format string, args ...interface{})
- func (l *Logger) RemovePeriodic(id string)
- func (l *Logger) RunAllPeriodic()
- func (l *Logger) Warning(format string, args ...interface{})
- func (l *Logger) WriteAdapter(level Level) io.Writer
Constants ¶
This section is empty.
Variables ¶
var DebugPeriodicIntervals = false
DebugPeriodicIntervals enables logging of periodic-logger intervals. After each logger is run the time until next run of that periodic logger is printed, as well as the time until any other logger if non-zero.
Functions ¶
func Escape ¶
Escape escapes multi-line NMEA sentences for debug logging. It replaces CR, LF and NUL with \r, \n and \0, and is only slightly longer than string().
func RoundDuration ¶
RoundDuration removes excessive precission for printing.
func SiMultiple ¶
SiMultiple rounds n down to the nearest Kilo, Mega, Giga, ..., or Yotta, and append the letter. `multipleOf` can be 1000 or 1024 (or anything >=256 (=(2^64)^(1/8))). `maxUnit` prevents losing too much precission by using too big units.
Types ¶
type Composer ¶
type Composer struct {
// contains filtered or unexported fields
}
Composer lets you split a long message into multiple write statements End the message by calling Finish() or Close()
func (*Composer) Close ¶
func (c *Composer) Close()
Close releases the mutex on the logger and exits the process for `Fatal` errors.
type Level ¶
type Level uint8
Level is the importance of a logged event
const ( Debug Level = iota // passed through without prepending timestamp Fatal // irrecoverable error Error // non-fatal but permanent degradation Warning // temporary degradation or transient IO error or client error Info // unimportant but noteworthy Ignore // don't print )
log message importance
type Logger ¶
type Logger struct { Treshold Level // contains filtered or unexported fields }
Logger is an utility for thread-safe and periodic logging. Use .Log() or one of its wrappers for issues that can be caught as they happen, PeriodicLogger for statistics and. Use .Compose() to make sure multi-statement messages get written as one. Should not be dereferenced or moved as it contains mutexes
func NewLogger ¶
func NewLogger(writeTo io.WriteCloser, treshold Level) *Logger
NewLogger creates a new logger with a minimum importance level and the interval to check the periodic loggers Even though Logger implements WriteCloser, Loggers should not be nested.
func (*Logger) AddPeriodic ¶
AddPeriodic stores a closure that will be called periodically with an interval that increases from minInterval to maxInterval exponentally.
func (*Logger) Debug ¶
Debug prints possibly interesting information, and is never filtered. Calls to this should probably not be committed.
func (*Logger) FatalIf ¶
FatalIf does nothing if cond is false, but otherwise prints the message and aborts the process.
func (*Logger) FatalIfErr ¶
FatalIfErr does nothing if err is nil, but otherwise prints "Failed to <..>: $err.Error()" and aborts the process.
func (*Logger) RemovePeriodic ¶
RemovePeriodic removes a periodic logger so that it will never be called again. If it doesn't exist an error is printed to the logger.
func (*Logger) RunAllPeriodic ¶
func (l *Logger) RunAllPeriodic()
RunAllPeriodic runs all the closures right now, ignoring any intervals.
func (*Logger) WriteAdapter ¶
WriteAdapter returns a Writer that writes through this logger with the given level. Writes that don't end in a newline are buffered to not split messages, but Composer-written messages might get split. The adapter is not synchronized because both the standard log.Logger and other instances of this type serializes writes, and the underlying Logger is synchronized.