Documentation ¶
Overview ¶
Package zapcloudlogging provides the Cloud Logging integration for Zap.
Index ¶
- Constants
- func Caller(skip int) (pc uintptr, file string, line int, ok bool)
- func Callers(skip int, pcs []uintptr) int
- func CallersFrames(callers []uintptr) *frames
- func ErrorReport(pc uintptr, file string, line int, ok bool) zap.Field
- func FuncForPC(pc uintptr) *runtime.Func
- func HTTP(req *HTTPPayload) zap.Field
- func Label(key, val string) zapcore.Field
- func Labels(keyvals ...string) zapcore.Field
- func NewCore(ws zapcore.WriteSyncer, enab zapcore.LevelEnabler, opts ...Option) zapcore.Core
- func NewEncoderConfig() zapcore.EncoderConfig
- func Operation(id, producer string, first, last bool) zapcore.Field
- func OperationCont(id, producer string) zapcore.Field
- func OperationEnd(id, producer string) zapcore.Field
- func OperationStart(id, producer string) zapcore.Field
- func ServiceContext(name string) zap.Field
- func SourceLocation(pc uintptr, file string, line int, ok bool) zapcore.Field
- func TraceField(traceID, spanID string, isSampled bool) []zapcore.Field
- func WrapCore(opts ...Option) zap.Option
- type Core
- type HTTPPayload
- type Option
Constants ¶
const ( // TraceKey is the resource name of the trace associated with the log entry if any. For more information. // // trace field: // - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace TraceKey = "logging.googleapis.com/trace" // SpanKey is the span ID within the trace associated with the log entry. For more information. // // spanId field: // - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.span_id SpanKey = "logging.googleapis.com/spanId" // TraceSampledKey is the value of this field must be either true or false. For more information. // // trace_sampled field: // - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace_sampled TraceSampledKey = "logging.googleapis.com/trace_sampled" )
const ( // HTTPRequestKey a structured record in the format of the LogEntry HttpRequest field. // // httpRequest field: // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.http_request // - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields HTTPRequestKey = "httpRequest" )
const ( // LabelsKeys is the value of this field must be a structured record. For more information. // // labels field: // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.labels LabelsKey = "logging.googleapis.com/labels" )
const ( // OperationKey is the value of this field is also used by the Logs Explorer to group related log entries. // // operation field: // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.operation // - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields OperationKey = "logging.googleapis.com/operation" )
const ( // SourceLocationKey is the Source code location information associated with the log entry, if any. // // sourceLocation field: // - https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.source_location // - https://cloud.google.com/logging/docs/structured-logging#special-payload-fields SourceLocationKey = "logging.googleapis.com/sourceLocation" )
Variables ¶
This section is empty.
Functions ¶
func Caller ¶
Caller is a drop-in replacement for runtime.Caller.
Token from: https://github.com/golang/go/blob/go1.19/src/runtime/extern.go#L217-L225
func Callers ¶
Callers is a drop-in replacement for runtime.Callers that uses frame pointers for fast and simple stack unwinding.
Based by: https://github.com/golang/go/blob/go1.19/src/runtime/extern.go#L240-L248
func CallersFrames ¶
func CallersFrames(callers []uintptr) *frames
CallersFrames is a drop-in replacement for runtime.CallersFrames.
CallersFrames takes a slice of PC values returned by Callers and prepares to return function/file/line information. Do not change the slice until you are done with the Frames.
Token from: https://github.com/golang/go/blob/go1.19/src/runtime/symtab.go#L66
func ErrorReport ¶
ErrorReport adds the Cloud Logging "context" field for getting the log line reported as error.
https://cloud.google.com/error-reporting/docs/formatting-error-messages
func HTTP ¶
func HTTP(req *HTTPPayload) zap.Field
HTTP adds the Cloud Logging "httpRequest" field.
httpRequest: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
func Label ¶
Label adds the Cloud Logging "labels" field from key and val.
Cloud Logging truncates label keys that exceed 512 B and label values that exceed 64 KB upon their associated log entry being written. The truncation is indicated by an ellipsis at the end of the character string.
func NewCore ¶
func NewCore(ws zapcore.WriteSyncer, enab zapcore.LevelEnabler, opts ...Option) zapcore.Core
NewCore creates a Core that writes logs to a WriteSyncer.
func NewEncoderConfig ¶
func NewEncoderConfig() zapcore.EncoderConfig
NewEncoderConfig returns the logging configuration.
func Operation ¶
Operation adds the Cloud Logging "operation" fields from args.
operation: 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 ServiceContext ¶
ServiceContext adds the service information adding the log line. It is a required field if an error needs to be reported.
ServiceContext: https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext
func SourceLocation ¶
SourceLocation adds the Cloud Logging "sourceLocation" field.
LogEntrySourceLocation: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation
func TraceField ¶
TraceField adds the correct Cloud Logging "trace", "span", "trace_sampled" fields from ctx.
https://cloud.google.com/logging/docs/agent/logging/configuration#special-fields
Types ¶
type Core ¶
type Core struct { zapcore.LevelEnabler // contains filtered or unexported fields }
Core represents a zapcor.Core that is Cloud Logging integration for Zap logger.
func (*Core) Check ¶
func (c *Core) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check determines whether the supplied Entry should be logged (using the embedded LevelEnabler and possibly some extra logic). If the entry should be logged, the Core adds itself to the CheckedEntry and returns the result.
Check implements zapcore.Core.Check.
type HTTPPayload ¶
type HTTPPayload struct {
*logtypepb.HttpRequest
}
HTTPPayload represents a Cloud Logging httpRequest fields.
func NewHTTPRequest ¶
func NewHTTPRequest(r *http.Request, res *http.Response) *HTTPPayload
NewHTTPRequest returns a new HTTPPayload struct, based on the passed in http.Request and http.Response objects.
func (*HTTPPayload) MarshalLogObject ¶
func (p *HTTPPayload) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore.ObjectMarshaler.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a core.
func WithInitialFields ¶
WithInitialFields configures the zap InitialFields.
func WithWriteSyncer ¶
func WithWriteSyncer(ws zapcore.WriteSyncer) Option
WithWriteSyncer configures the zapcore.WriteSyncer.