Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(format string, v ...interface{})
- func Error(format string, v ...interface{})
- func Info(format string, v ...interface{})
- func Printf(format string, v ...interface{})
- func Sync()
- func Time(format string, v ...interface{}) func()
- func Warn(format string, v ...interface{})
- type Features
- type Level
- type Logger
- func (l *Logger) Close()
- func (l *Logger) Debug(format string, v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) DisableFeatures(disableFeats Features)
- func (l *Logger) EnableFeatures(enableFeats Features)
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) GoLogger(forLevel Level) *log.Logger
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Log(level Level, format string, v ...interface{})
- func (l *Logger) LogDebug(calldepth int, format string, v ...interface{})
- func (l *Logger) SetWriter(w io.Writer)
- func (l *Logger) SubLogger(addPrefix string) *Logger
- func (l *Logger) Sync() error
- func (l *Logger) Time(format string, v ...interface{}) func()
- func (l *Logger) Warn(format string, v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- func (l *Logger) Writer() io.Writer
Constants ¶
const ( FDate Features = 1 << iota // include date (format YYYY-MM-DD) FTime // include time (format HH:MM:SS) FMilliseconds // include milliseconds in time (format Time.sss) FMicroseconds // include microseconds in time (format Time.ssssss) FUTC // date & time in UTC rather than local time zone FDebugOrigin // include source file at end of debug messages FColor // enable ANSI terminal colors FColorAuto // enable FColor if w is TTY & env TERM supports colors FPrefixDebug = 1 << (fPrefixBitOffs + LevelDebug) // enable prefix for LevelDebug ("[debug]") FPrefixInfo = 1 << (fPrefixBitOffs + LevelInfo) // enable prefix for LevelInfo ("[info]") FPrefixWarn = 1 << (fPrefixBitOffs + LevelWarn) // enable prefix for LevelWarn ("[warn]") FPrefixError = 1 << (fPrefixBitOffs + LevelError) // enable prefix for LevelError ("[error]") FSyncDebug = 1 << (fSyncBitOffs + LevelDebug) // write debug messages in a blocking fashion FSyncInfo = 1 << (fSyncBitOffs + LevelInfo) // write info messages in a blocking fashion FSyncWarn = 1 << (fSyncBitOffs + LevelWarn) // write warning messages in a blocking fashion FSyncError = 1 << (fSyncBitOffs + LevelError) // write error messages in a blocking fashion FSync = FSyncDebug | FSyncInfo | FSyncWarn | FSyncError FDefault = FTime | FDebugOrigin | FColorAuto | FPrefixDebug | FPrefixInfo | FPrefixWarn | FPrefixError )
Variables ¶
Functions ¶
Types ¶
type Logger ¶
func (*Logger) DisableFeatures ¶
func (*Logger) EnableFeatures ¶
func (*Logger) GoLogger ¶
GoLogger returns a go log.Logger that mirrors this logger. Useful for APIs that specifically requires a go Logger.
forLevel should be the level of logging that the Go logger will be used for. For example, if this is to be used for debugging, call GoLogger(LevelDebug). In case forLevel is less than l.Level a null logger is returned. This way the level of the receiver has an effect on the Go logger.
Example:
logger.Level = log.LevelWarn goLoggerInfo := logger.GoLogger(log.LevelInfo) goLoggerWarn := logger.GoLogger(log.LevelWarn) goLoggerInfo.Printf("Hello") // (nothing is printed) goLoggerWarn.Printf("oh no") // "oh no" is printed
func (*Logger) Sync ¶
Sync returns when all messages have been written. If the process exits after a Sync call all messages up to that point are guaranteed to be written, assuming the OS kernel doesn't terminate (i.e. from power failure.)
func (*Logger) Time ¶
Time starts a time measurement, logged when the returned function is invoked. Call the returned function to measure time taken since the call to l.Time and log a message.
"thing with 123: 6.597116ms"
Time uses LevelInfo
Example: Log time spent in a function:
func foo(thing int) { defer log.Time("foo with thing %d", thing)() ... }
Output:
"[time] foo with thing 123: 6.597116ms"