https://github.com/baobabus/slog
Structured logging for go.
https://github.com/baobabus/slog
Last synced: 6 months ago
JSON representation
Structured logging for go.
- Host: GitHub
- URL: https://github.com/baobabus/slog
- Owner: baobabus
- License: mit
- Created: 2016-02-18T14:15:47.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-08-19T23:02:43.000Z (almost 6 years ago)
- Last Synced: 2025-01-02T22:22:50.770Z (over 1 year ago)
- Language: Go
- Size: 1.15 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slog
Structured logging for go.
[](https://travis-ci.org/baobabus/slog)
# Usage
Example logging with global logger:
```go
package main
import (
"errors"
"github.com/baobabus/slog"
"time"
)
func emit(i int) error {
if i % 2 == 0 {
return errors.New("Bad input")
}
return nil
}
func main () {
slog.Info().Prints("Starting conditional", "time", time.Now())
for i := 0; i < 4; i++ {
err := emit(i)
slog.On(err).Prints("Problem with emit():", "i", i)
}
slog.Info().Prints("Finished conditional", "time", time.Now())
slog.Info().Prints("Starting unconditional", "time", time.Now())
for i := 0; i < 4; i++ {
err := emit(i)
slog.With(err).Prints("Returned from emit():", "i", i)
}
slog.Info().Prints("Finished unconditional", "time", time.Now())
}
```
Output:
```
INFO 2016/07/20 11:23:58 Starting conditional time=2016-07-20T11:23:58-05:00
ERROR 2016/07/20 11:23:58 Problem with emit(): i=0 - error=Bad input
ERROR 2016/07/20 11:23:58 Problem with emit(): i=2 - error=Bad input
INFO 2016/07/20 11:23:58 Finished conditional time=2016-07-20T11:23:58-05:00
INFO 2016/07/20 11:23:58 Starting unconditional time=2016-07-20T11:23:58-05:00
ERROR 2016/07/20 11:23:58 Returned from emit(): i=0 - error=Bad input
NOTICE 2016/07/20 11:23:58 Returned from emit(): i=1 - success
ERROR 2016/07/20 11:23:58 Returned from emit(): i=2 - error=Bad input
NOTICE 2016/07/20 11:23:58 Returned from emit(): i=3 - success
INFO 2016/07/20 11:23:58 Finished unconditional time=2016-07-20T11:23:58-05:00
```