https://github.com/datainq/sdfmt
Stackdriver formatter for logrus
https://github.com/datainq/sdfmt
Last synced: 5 months ago
JSON representation
Stackdriver formatter for logrus
- Host: GitHub
- URL: https://github.com/datainq/sdfmt
- Owner: datainq
- License: mit
- Created: 2019-02-08T13:38:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-14T15:29:28.000Z (over 1 year ago)
- Last Synced: 2025-08-13T23:52:32.156Z (10 months ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sdfmt [](https://travis-ci.org/datainq/sdfmt)
Stackdriver formatter for [logrus](https://github.com/sirupsen/logrus) logger compliant with [Stackdriver Logging API](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).
## Installation
`go get -u github.com/datainq/sdfmt`
## Usage
```go
package main
import (
"github.com/datainq/sdfmt"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&sdfmt.StackdriverFormatter{})
log.WithFields(log.Fields{
"animal": "walrus",
}).Info("A walrus appears")
}
```
Output:
`{"labels":{"animal":"walrus"},"message":"A walrus appears","severity":200,"timestamp":"2019-03-31T18:35:13.752104+02:00"}`
## Logging levels association
| `logrus.Level` | Stackdriver's `LogSeverity` |
|:----------------------------------------:|:---------------------------:|
| - | DEFAULT (0) |
| `logrus.TraceLevel`, `logrus.DebugLevel` | DEBUG (100) |
| `logrus.InfoLevel` | INFO (200) |
| - | NOTICE (300) |
| `logrus.WarnLevel` | WARNING (400) |
| `logrus.ErrorLevel` | ERROR (500) |
| - | CRITICAL (600) |
| - | ALERT (700) |
| `logrus.FatalLevel`, `logrus.PanicLevel` | EMERGENCY (800) |