mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
95401434a2
Former-commit-id: 900e1a398fd82aa1cea4f319e89b8088dd81cf6c [formerly f172c22b12c49c0291e0d986dc4af94fcc91d192] [formerly 43c5da81442a5f0ca79a6eabb1dfdfbfb3f22680 [formerly 7a39ef2b52fc10e7c980d377dbd52f5340e4e53a [formerly2694d0b183
]]] Former-commit-id: fa39d6a984adc4ca8f8c82c5df145c336885a53f [formerly 94543f8081bc18b1a39daf8500cfa7e0b1ba7393] Former-commit-id: 809aae62e28a3f99a01854f71fcd5a85f89d2972 Former-commit-id:e8a4d30139
1.4 KiB
1.4 KiB
lumber
A simple logger for Go.
Provides console and file loggers that support 6 log levels. The file logger supports log backup and rotation.
Usage:
Log to the default (console) logger
lumber.Error("An error message")
Create a new console logger that only logs messages of level WARN or higher
log := lumber.NewConsoleLogger(lumber.WARN)
Change the log level for a logger
log.Level(lumber.INFO)
Create a new file logger that rotates at 5000 lines (up to 9 backups) with a 100 message buffer
log := lumber.NewFileLogger("filename.log", lumber.INFO, lumber.ROTATE, 5000, 9, 100)
// or
log := lumber.NewRotateLogger("filename.log", 5000, 9)
Send messages to the log
// the log methods use fmt.Printf() syntax
log.Trace("the %s log level", "lowest")
log.Debug("")
log.Info("the default log level")
log.Warn("")
log.Error("")
log.Fatal("the %s log level", "highest")
Add a prefix to label different logs
log.Prefix("MYAPP")
Use a MultiLogger
mlog := NewMultiLogger()
mlog.AddLoggers(log1, log2)
mlog.Warn("This message goes to multiple loggers")
mlog.Close() // closes all loggers
Modes:
APPEND: Append if the file exists, otherwise create a new file
TRUNC: Open and truncate the file, regardless of whether it already exists
BACKUP: Rotate the log every time a new logger is created
ROTATE: Append if the file exists, when the log reaches maxLines rotate files