Documentation
¶
Index ¶
- func EncodeLevel(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func ErrorReport(pc uintptr, file string, line int, ok bool) zap.Field
- func HTTP(req *HTTPPayload) zap.Field
- func Label(key, value string) zap.Field
- func Labels(fields ...zap.Field) zap.Field
- func NewDevelopment(options ...zap.Option) (*zap.Logger, error)
- func NewDevelopmentConfig() zap.Config
- func NewDevelopmentEncoderConfig() zapcore.EncoderConfig
- func NewDevelopmentWithCore(core zap.Option, options ...zap.Option) (*zap.Logger, error)
- func NewProduction(options ...zap.Option) (*zap.Logger, error)
- func NewProductionConfig() zap.Config
- func NewProductionEncoderConfig() zapcore.EncoderConfig
- func NewProductionWithCore(core zap.Option, options ...zap.Option) (*zap.Logger, error)
- func Operation(id, producer string, first, last bool) zap.Field
- func OperationCont(id, producer string) zap.Field
- func OperationEnd(id, producer string) zap.Field
- func OperationStart(id, producer string) zap.Field
- func RFC3339NanoTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func ReportAllErrors(report bool) func(*core)
- func ServiceContext(name string) zap.Field
- func ServiceName(name string) func(*core)
- func SourceLocation(pc uintptr, file string, line int, ok bool) zap.Field
- func TraceContext(trace string, spanId string, sampled bool, projectName string) []zap.Field
- func WrapCore(options ...func(*core)) zap.Option
- type HTTPPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeLevel ¶
func EncodeLevel(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
EncodeLevel maps the internal Zap log level to the appropriate Stackdriver level.
func ErrorReport ¶ added in v1.2.0
ErrorReport adds the correct Stackdriver "context" field for getting the log line reported as error.
see: https://cloud.google.com/error-reporting/docs/formatting-error-messages
func HTTP ¶
func HTTP(req *HTTPPayload) zap.Field
HTTP adds the correct Stackdriver "HTTP" field.
see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
func Label ¶
Label adds an optional label to the payload.
Labels are a set of user-defined (key, value) data that provides additional information about the log entry.
Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
func Labels ¶
Labels takes Zap fields, filters the ones that have their key start with the string `labels.` and their value type set to StringType. It then wraps those key/value pairs in a top-level `labels` namespace.
func NewDevelopment ¶
NewDevelopment builds a development Logger that writes DebugLevel and above logs to standard error in a human-friendly format.
It's a shortcut for NewDevelopmentConfig().Build(...Option).
func NewDevelopmentConfig ¶
NewDevelopmentConfig is a reasonable development logging configuration. Logging is enabled at DebugLevel and above.
It enables development mode (which makes DPanicLevel logs panic), uses a console encoder, writes to standard error, and disables sampling. Stacktraces are automatically included on logs of WarnLevel and above.
func NewDevelopmentEncoderConfig ¶
func NewDevelopmentEncoderConfig() zapcore.EncoderConfig
NewDevelopmentEncoderConfig returns an opinionated EncoderConfig for development environments.
func NewDevelopmentWithCore ¶ added in v1.2.0
NewDevelopmentWithCore is same as NewDevelopment but accepts a custom configured core
func NewProduction ¶
NewProduction builds a sensible production Logger that writes InfoLevel and above logs to standard error as JSON.
It's a shortcut for NewProductionConfig().Build(...Option).
func NewProductionConfig ¶
NewProductionConfig is a reasonable production logging configuration. Logging is enabled at InfoLevel and above.
It uses a JSON encoder, writes to standard error, and enables sampling. Stacktraces are automatically included on logs of ErrorLevel and above.
func NewProductionEncoderConfig ¶
func NewProductionEncoderConfig() zapcore.EncoderConfig
NewProductionEncoderConfig returns an opinionated EncoderConfig for production environments.
func NewProductionWithCore ¶ added in v1.2.0
NewProductionWithCore is same as NewProduction but accepts a custom configured core
func Operation ¶
Operation adds the correct Stackdriver "operation" field.
Additional information about a potentially long-running operation with which a log entry is associated.
see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntryOperation
func OperationCont ¶
OperationCont is a convenience function for `Operation`. It should be called for any non-start/end operation log.
func OperationEnd ¶
OperationEnd is a convenience function for `Operation`. It should be called for the last operation log.
func OperationStart ¶
OperationStart is a convenience function for `Operation`. It should be called for the first operation log.
func RFC3339NanoTimeEncoder ¶
func RFC3339NanoTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
RFC3339NanoTimeEncoder serializes a time.Time to an RFC3339Nano-formatted string with nanoseconds precision.
func ReportAllErrors ¶ added in v1.2.0
func ReportAllErrors(report bool) func(*core)
zapdriver core option to report all logs with level error or above to stackdriver using `ErrorReport()` when set to true
func ServiceContext ¶ added in v1.2.0
ServiceContext adds the correct service information adding the log line It is a required field if an error needs to be reported.
see: https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext see: https://cloud.google.com/error-reporting/docs/formatting-error-messages
func ServiceName ¶ added in v1.2.0
func ServiceName(name string) func(*core)
zapdriver core option to add `ServiceContext()` to all logs with `name` as service name
func SourceLocation ¶
SourceLocation adds the correct Stackdriver "SourceLocation" field.
see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation
func TraceContext ¶ added in v1.3.0
TraceContext adds the correct Stackdriver "trace", "span", "trace_sampled fields
see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
Types ¶
type HTTPPayload ¶
type HTTPPayload 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"`
}
HTTPPayload is the complete payload that can be interpreted by Stackdriver as a HTTP request.
func NewHTTP ¶
func NewHTTP(req *http.Request, res *http.Response) *HTTPPayload
NewHTTP returns a new HTTPPayload struct, based on the passed in http.Request and http.Response objects.
func (HTTPPayload) MarshalLogObject ¶
func (req HTTPPayload) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore.ObjectMarshaller interface.