https://github.com/borislavv/go-logger
Simple wrapper over the Logrus logger.
https://github.com/borislavv/go-logger
golang library logrus wrapper
Last synced: over 1 year ago
JSON representation
Simple wrapper over the Logrus logger.
- Host: GitHub
- URL: https://github.com/borislavv/go-logger
- Owner: Borislavv
- License: apache-2.0
- Created: 2024-09-26T10:25:29.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-11T11:19:58.000Z (over 1 year ago)
- Last Synced: 2025-02-04T15:27:23.037Z (over 1 year ago)
- Topics: golang, library, logrus, wrapper
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Logrus logger wrapper.
### ENVs:
1. **LOGGER_LEVEL** (values: info, debug, warning, error, fatal, panic)
2. **LOGGER_OUTPUT** (values: /dev/null/, stdout, stderr, filename (example: /var/log/dev.log))
3. **LOGGER_FORMAT** (values: text, json)
4. **LOGGER_LOGS_DIR** (values: any dir from root project dir., for example: var/log)
5. **LOGGER_CONTEXT_EXTRA_FIELD** (any values which will extracts from context.Context, for example: jobID, taskID)
### Usage:
cfg, err := loggerconfig.Load()
if err != nil {
panic(err)
}
output, cancelOutput, err := logger.NewOutput(cfg)
if err != nil {
panic(err)
}
defer cancelOutput()
lgr, lgrCancel, err := logger.NewLogrus(cfg, output)
if err != nil {
panic(err)
}
defer lgrCancel()
lgr.InfoMsg(ctx, "hello world", logger.Fields{
"error": "no-errors",
"any": "additional fields",
})
### Note:
An **output, cancelOutput, err := logger.NewOutput()** must be called just once per unique output, or you will see an error
of closing already closed file while canceling the output. This happens due to two outputs refers to the same file pointer.
**Example:**
output1, cancelOutput1, _ := logger.NewOutput("stdout")
output2, cancelOutput2, _ := logger.NewOutput("stdout")
cancelOutput1() // ok
cancelOutput2() // error: closing file already closed