Documentation ¶
Overview ¶
Package stackdriver implements a Stackdriver LogEntry support for zap package.
Index ¶
- func LevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func LogContext(ctx *Context) zapcore.Field
- func LogHTTPRequest(req *HTTPRequest) zap.Field
- func LogHttpRequest(req *HttpRequest) zap.Field
- func LogReportLocation(loc *ReportLocation) zapcore.Field
- func LogServiceContext(sc *ServiceContext) zapcore.Field
- func LogSourceLocation(pc uintptr, file string, line int, ok bool) zap.Field
- func LogUser(user string) zapcore.Field
- func NewStackdriverConfig() zap.Config
- func NewStackdriverEncoder(ctx context.Context, encoderConfig zapcore.EncoderConfig, ...) zapcore.Encoder
- func NewStackdriverEncoderConfig() zapcore.EncoderConfig
- func RegisterStackdriverEncoder(ctx context.Context, projectID, logID string) (string, func(zapcore.EncoderConfig) (zapcore.Encoder, error))
- type Context
- type Encoder
- type HTTPRequest
- type HttpRequest
- type ReportLocation
- type ServiceContext
- type SourceLocation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LevelEncoder ¶ added in v0.0.2
func LevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
func LogContext ¶ added in v0.0.5
func LogHTTPRequest ¶ added in v0.0.5
func LogHTTPRequest(req *HTTPRequest) zap.Field
LogHTTPPayload adds the correct Stackdriver "HttpRequest" field.
ref: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
func LogHttpRequest ¶ added in v0.0.5
func LogHttpRequest(req *HttpRequest) zap.Field
LogHttpRequest adds the correct Stackdriver "HttpRequest" field.
func LogReportLocation ¶ added in v0.0.3
func LogReportLocation(loc *ReportLocation) zapcore.Field
func LogServiceContext ¶ added in v0.0.5
func LogServiceContext(sc *ServiceContext) zapcore.Field
func LogSourceLocation ¶ added in v0.0.5
LogSourceLocation adds the correct Stackdriver "SourceLocation" field.
func NewStackdriverConfig ¶
NewStackdriverConfig returns the stackdriver encoder zap.Config.
func NewStackdriverEncoder ¶
func NewStackdriverEncoder(ctx context.Context, encoderConfig zapcore.EncoderConfig, projectID, logID string) zapcore.Encoder
NewStackdriverEncoder returns the stackdriver zapcore.Encoder.
func NewStackdriverEncoderConfig ¶
func NewStackdriverEncoderConfig() zapcore.EncoderConfig
NewStackdriverEncoderConfig returns the new zapcore.EncoderConfig with stackdriver encoder config.
Types ¶
type Context ¶ added in v0.0.2
type Context struct { User string `json:"user"` HTTPRequest *HTTPRequest `json:"httpRequest"` ReportLocation *ReportLocation `json:"reportLocation"` }
func (*Context) MarshalLogObject ¶ added in v0.0.2
func (c *Context) MarshalLogObject(enc zapcore.ObjectEncoder) (err error)
type Encoder ¶
type Encoder struct { SetReportLocation bool zapcore.Encoder *zapcore.EncoderConfig // contains filtered or unexported fields }
func (*Encoder) EncodeEntry ¶
func (*Encoder) ReportLocationFromEntry ¶ added in v0.0.5
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 ¶ added in v0.0.2
func (req *HTTPRequest) Clone() *HTTPRequest
func (*HTTPRequest) MarshalLogObject ¶
func (req *HTTPRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error
type HttpRequest ¶ added in v0.0.5
type HttpRequest struct { // The request method. Examples: "GET", "HEAD", "PUT", "POST". RequestMethod string `json:"requestMethod"` // The scheme (http, https), the host name, the path and the query portion of // the URL that was requested. // // Example: "http://example.com/some/info?color=red". RequestURL string `json:"requestUrl"` // The size of the HTTP request message in bytes, including the request // headers and the request body. RequestSize string `json:"requestSize"` // The response code indicating the status of response. // // Examples: 200, 404. Status int `json:"status"` // The size of the HTTP response message sent back to the client, in bytes, // including the response headers and the response body. ResponseSize string `json:"responseSize"` // The user agent sent by the client. // // Example: "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)". UserAgent string `json:"userAgent"` // The IP address (IPv4 or IPv6) of the client that issued the HTTP request. // // Examples: "192.168.1.1", "FE80::0202:B3FF:FE1E:8329". RemoteIP string `json:"remoteIp"` // The IP address (IPv4 or IPv6) of the origin server that the request was // sent to. ServerIP string `json:"serverIp"` // The referrer URL of the request, as defined in HTTP/1.1 Header Field // Definitions. Referer string `json:"referer"` // The request processing latency on the server, from the time the request was // received until the response was sent. // // A duration in seconds with up to nine fractional digits, terminated by 's'. // // Example: "3.5s". Latency string `json:"latency"` // Whether or not a cache lookup was attempted. CacheLookup bool `json:"cacheLookup"` // Whether or not an entity was served from cache (with or without // validation). CacheHit bool `json:"cacheHit"` // Whether or not the response was validated with the origin server before // being served from cache. This field is only meaningful if cacheHit is True. CacheValidatedWithOriginServer bool `json:"cacheValidatedWithOriginServer"` // The number of HTTP response bytes inserted into cache. Set only when a // cache fill was attempted. CacheFillBytes string `json:"cacheFillBytes"` // Protocol used for the request. // // Examples: "HTTP/1.1", "HTTP/2", "websocket" Protocol string `json:"protocol"` }
HttpRequest represents a common proto for logging HTTP requests.
Only contains semantics defined by the HTTP specification. Product-specific logging information MUST be defined in a separate message.
https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest
func NewHHttpRequest ¶ added in v0.0.5
func NewHHttpRequest(req *http.Request, resp *http.Response) *HttpRequest
NewHttpRequest returns a new HttpRequest struct, based on the passed in http.Request and http.Response objects.
func (*HttpRequest) Clone ¶ added in v0.0.5
func (req *HttpRequest) Clone() *HttpRequest
Clone implements zapcore.Encoder.
func (*HttpRequest) MarshalLogObject ¶ added in v0.0.5
func (req *HttpRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore.ObjectMarshaler.
type ReportLocation ¶ added in v0.0.2
type ReportLocation struct { FilePath string `json:"filePath"` LineNumber int `json:"lineNumber"` FunctionName string `json:"functionName"` }
func (*ReportLocation) Clone ¶ added in v0.0.2
func (r *ReportLocation) Clone() *ReportLocation
func (*ReportLocation) MarshalLogObject ¶ added in v0.0.2
func (r *ReportLocation) MarshalLogObject(enc zapcore.ObjectEncoder) error
type ServiceContext ¶
func (*ServiceContext) Clone ¶ added in v0.0.2
func (sc *ServiceContext) Clone() *ServiceContext
func (*ServiceContext) MarshalLogObject ¶
func (sc *ServiceContext) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore ObjectMarshaler.
type SourceLocation ¶ added in v0.0.5
type SourceLocation struct { // Optional. Source file name. Depending on the runtime environment, this might // be a simple name or a fully-qualified name. File string `json:"file"` // Optional. Line within the source file. 1-based; 0 indicates no line number // available. Line string `json:"line"` // Optional. Human-readable name of the function or method being invoked, with // optional context such as the class or package name. This information may be // used in contexts such as the logs viewer, where a file and line number are less // meaningful. // // The format should be dir/package.func. Function string `json:"function"` }
SourceLocation additional information about the source code location that produced the log entry.
https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logentrysourcelocation
func NewSourceLocation ¶ added in v0.0.5
func NewSourceLocation(pc uintptr, file string, line int, ok bool) *SourceLocation
NewSourceLocation returns a new SourceLocation struct, based on the pc, file, line and ok arguments.
func (*SourceLocation) Clone ¶ added in v0.0.5
func (sl *SourceLocation) Clone() *SourceLocation
Clone implements zapcore.Encoder.
func (SourceLocation) MarshalLogObject ¶ added in v0.0.5
func (sl SourceLocation) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore.ObjectMarshaler.