2022-02-05 10:02:25 +00:00
|
|
|
# Go Basic Logger
|
|
|
|
|
|
|
|
A basic logger written in Go so simple it's impossible to miss it.
|
2022-02-05 10:03:28 +00:00
|
|
|
|
|
|
|
## Log levels
|
|
|
|
|
|
|
|
| Level | Alias | Description |
|
|
|
|
|----------|-------|-------------------------------------------------------------------------------------|
|
|
|
|
| DEBUG | DBG | Debug information useful when programming |
|
|
|
|
| NOTICE | NOT | Notice information useful when requesting logs for errors/bugs |
|
|
|
|
| INFO | INF | Standard classic log level, general information that narrates the program execution |
|
|
|
|
| WARNING | WRN | Warning messages for non-blocking things that go wrong |
|
|
|
|
| ERROR | ERR | Error messages for non-blocking things that go wrong |
|
|
|
|
| CRITICAL | CRT | Critical messages it's mandatory to pay attention to, may be still non-blocking |
|
|
|
|
| FATAL | FAT | Fatal messages about things for which the program execution cannot continue |
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
General usage:
|
|
|
|
```
|
|
|
|
package main
|
|
|
|
|
2022-03-26 10:53:47 +00:00
|
|
|
import gobasiclogger "git.bjphoster.com/b.pedini/go-basic-logger"
|
2022-03-26 10:38:42 +00:00
|
|
|
|
2022-03-26 10:53:47 +00:00
|
|
|
var logger gobasiclogger.Logger
|
2022-02-05 10:03:28 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
logLevel := "DEBUG"
|
2022-03-26 10:53:47 +00:00
|
|
|
logger = *new(gobasiclogger.Logger)
|
2022-02-05 10:03:28 +00:00
|
|
|
logger.Initialize(&logLevel)
|
|
|
|
logger.Debug("Program execution started")
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal("Received error during operation X:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Getting the Logger level from an environment variable (called LOGLEVEL, not customizable (yet)):
|
|
|
|
```
|
|
|
|
...
|
|
|
|
|
|
|
|
func main() {
|
2022-03-26 10:53:47 +00:00
|
|
|
logger = *new(gobasiclogger.Logger)
|
2022-02-05 10:03:28 +00:00
|
|
|
logger.Initialize(nil)
|
|
|
|
|
|
|
|
...
|
|
|
|
}
|
|
|
|
```
|