Documentation
¶
Overview ¶
Example (Basic) ¶
package main import ( stackdriver "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", })) }
Output:
Index ¶
- Variables
- func EncodeLevel(lv zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func LogHTTPRequest(req *HTTPRequest) zapcore.Field
- func LogReportLocation(loc *ReportLocation) zapcore.Field
- func LogServiceContext(ctx *ServiceContext) zapcore.Field
- func LogUser(user string) zapcore.Field
- type Context
- type Core
- type HTTPRequest
- type ReportLocation
- type ServiceContext
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( EncoderConfig = zapcore.EncoderConfig{ TimeKey: "eventTime", LevelKey: "severity", NameKey: "logger", CallerKey: "caller", MessageKey: "message", StacktraceKey: "stacktrace", LineEnding: zapcore.DefaultLineEnding, EncodeLevel: EncodeLevel, EncodeTime: zapcore.ISO8601TimeEncoder, EncodeDuration: zapcore.SecondsDurationEncoder, EncodeCaller: zapcore.ShortCallerEncoder, } )
nolint: gochecknoglobals
Functions ¶
func EncodeLevel ¶
func EncodeLevel(lv zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
func LogHTTPRequest ¶
func LogHTTPRequest(req *HTTPRequest) zapcore.Field
func LogReportLocation ¶
func LogReportLocation(loc *ReportLocation) zapcore.Field
func LogServiceContext ¶
func LogServiceContext(ctx *ServiceContext) zapcore.Field
Types ¶
type Context ¶
type Context struct { User string `json:"user"` HTTPRequest *HTTPRequest `json:"httpRequest"` ReportLocation *ReportLocation `json:"reportLocation"` }
func (*Context) MarshalLogObject ¶
func (c *Context) MarshalLogObject(e zapcore.ObjectEncoder) (err error)
type Core ¶
func (*Core) Check ¶
func (c *Core) Check(entry zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
type HTTPRequest ¶
type HTTPRequest struct { Method string `json:"method"` URL string `json:"url"` UserAgent string `json:"userAgent"` Referrer string `json:"referrer"` ResponseStatusCode int `json:"responseStatusCode"` RemoteIP string `json:"remoteIp"` }
func (*HTTPRequest) Clone ¶
func (h *HTTPRequest) Clone() *HTTPRequest
func (*HTTPRequest) MarshalLogObject ¶
func (h *HTTPRequest) MarshalLogObject(e zapcore.ObjectEncoder) error
type ReportLocation ¶
func (*ReportLocation) Clone ¶
func (r *ReportLocation) Clone() *ReportLocation
func (*ReportLocation) MarshalLogObject ¶
func (r *ReportLocation) MarshalLogObject(e zapcore.ObjectEncoder) error
type ServiceContext ¶
func (*ServiceContext) Clone ¶
func (s *ServiceContext) Clone() *ServiceContext
func (*ServiceContext) MarshalLogObject ¶
func (s *ServiceContext) MarshalLogObject(e zapcore.ObjectEncoder) error
Click to show internal directories.
Click to hide internal directories.