log/README.md
2023-04-30 20:58:44 +02:00

41 lines
1.1 KiB
Markdown

# log
Package log provides a uniform method of logging.
## how to use this?
just import this module into your Go project by adding the following
line to your imports:
```go
"git.stinnesbeck.com/go/log"
```
You can use this package in your code as follows:
```go
log.Print(LOGLEVEL, "This is your message of type LOGLEVEL")
log.PrintInfo("This is your info message")
log.PrintWarning("This is your warning message")
log.PrintError("This is your error message")
log.PrintDebug("This is your debug message")
```
## Log levels
The following log levels are supported:
| LogLevel | Name |
|----------|---------|
| 0 | ERROR |
| 1 | WARNING |
| 2 | INFO |
| 3 | DEBUG |
The package will honor a globally set environment variable `LOGLEVEL`. The package will only print levels that are less or equal than the one provided (e.g. `WARNING` will only print `ERROR` and `WARNING`). If no environment variable is set or it can't be parsed into the names above, ERROR will be selected as the default.
## Example usage
You can see an example output by cloning this repo and executing:
```go
go test
```