Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tommy351/zap-stackdriver
Prints Stackdriver format logs with zap.
https://github.com/tommy351/zap-stackdriver
golang golang-library golang-package logging zap zap-stackdriver
Last synced: 3 months ago
JSON representation
Prints Stackdriver format logs with zap.
- Host: GitHub
- URL: https://github.com/tommy351/zap-stackdriver
- Owner: tommy351
- License: mit
- Created: 2017-09-17T06:23:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-16T15:49:48.000Z (over 2 years ago)
- Last Synced: 2024-10-11T20:48:08.741Z (4 months ago)
- Topics: golang, golang-library, golang-package, logging, zap, zap-stackdriver
- Language: Go
- Homepage: https://pkg.go.dev/github.com/tommy351/zap-stackdriver
- Size: 19.5 KB
- Stars: 34
- Watchers: 4
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zap-stackdriver
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/tommy351/zap-stackdriver)](https://github.com/tommy351/zap-stackdriver/releases) [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/tommy351/zap-stackdriver) ![Test](https://github.com/tommy351/zap-stackdriver/workflows/Test/badge.svg) [![codecov](https://codecov.io/gh/tommy351/zap-stackdriver/branch/master/graph/badge.svg)](https://codecov.io/gh/tommy351/zap-stackdriver)
Prints [Stackdriver format](https://cloud.google.com/error-reporting/docs/formatting-error-messages) logs with [zap](https://github.com/uber-go/zap).
## Installation
``` sh
go get github.com/tommy351/zap-stackdriver
```## Usage
``` go
package mainimport (
"github.com/tommy351/zap-stackdriver"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)func main() {
config := &zap.Config{
Level: zap.NewAtomicLevelAt(zapcore.InfoLevel),
Encoding: "json",
EncoderConfig: stackdriver.EncoderConfig,
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}logger, err := config.Build(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return &stackdriver.Core{
Core: core,
}
}), zap.Fields(
stackdriver.LogServiceContext(&stackdriver.ServiceContext{
Service: "foo",
Version: "bar",
}),
))if err != nil {
panic(err)
}logger.Info("Hello",
stackdriver.LogUser("token"),
stackdriver.LogHTTPRequest(&stackdriver.HTTPRequest{
Method: "GET",
URL: "/foo",
UserAgent: "bar",
Referrer: "baz",
ResponseStatusCode: 200,
RemoteIP: "1.2.3.4",
}))
}
```