https://github.com/13rac1/spotlog
A spotlight to locate important logs - A Go logging library extending logrus to increase log relevancy.
https://github.com/13rac1/spotlog
golang logging logging-library logrus
Last synced: 6 months ago
JSON representation
A spotlight to locate important logs - A Go logging library extending logrus to increase log relevancy.
- Host: GitHub
- URL: https://github.com/13rac1/spotlog
- Owner: 13rac1
- Created: 2020-04-24T19:25:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-28T22:02:14.000Z (over 5 years ago)
- Last Synced: 2025-03-14T21:12:59.249Z (10 months ago)
- Topics: golang, logging, logging-library, logrus
- Language: Go
- Homepage:
- Size: 1.12 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spot Log
**A spotlight to locate important logs**
Every log system provides log levels: set the minimum output level and throw out
the rest. The goal is to avoid wasting resources on necessary details. Those
details can be important though. Have you every thought: _"I wish I had the
debug logs for this error!"_
Spot Log stores logs below the level, then outputs all logs when a log above the
level is received.
Spot Log wraps Logrus implementing 95% the same interface.
## Usage
The `SpotLogger` instance is stored within the application or request `context`.
Get it from the `context` and use like any other logger.
```go
func passingCalc(ctx context.Context, w http.ResponseWriter) {
_, logger := spotlog.Get(ctx)
logger.Debug("passed calc")
w.WriteHeader(http.StatusOK)
}
func failingCalc(ctx context.Context, w http.ResponseWriter) {
_, logger := spotlog.Get(ctx)
logger.Error("failed calc")
w.WriteHeader(http.StatusInternalServerError)
}
func main() {
passingHandler := func(w http.ResponseWriter, req *http.Request) {
ctx, logger := spotlog.Get(req.Context())
logger.Debug("request received")
passingCalc(ctx, w)
// Output: nil
}
http.HandleFunc("/pass", passingHandler)
failingHandler := func(w http.ResponseWriter, req *http.Request) {
ctx, logger := spotlog.Get(req.Context())
logger.Debug("request received")
failingCalc(ctx, w)
// Output:
// level=debug msg="request received"
// level=error msg="failed calc"
}
http.HandleFunc("/fail", failingHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
```
## Ideas
* Logger data fields as global fields. Compare to the existing Entry fields
which are attached to an Entry.
* Print an Entry, but not all stored entries. Probably best at the `Info` level.