### Example usage of Labels Source: https://pkg.go.dev/github.com/blendle/zapdriver Applying multiple labels to a log entry. ```go logger.Info( "Did something.", zapdriver.Labels( zapdriver.Label("hello", "world"), zapdriver.Label("hi", "universe"), ), ) ``` -------------------------------- ### Example usage of Operation Source: https://pkg.go.dev/github.com/blendle/zapdriver Grouping logs for a single operation using start and end flags. ```go logger.Info("Started.", zapdriver.Operation("3g4d3g", "my-app", true, false)) logger.Debug("Progressing.", zapdriver.Operation("3g4d3g", "my-app", false, false)) logger.Info("Done.", zapdriver.Operation("3g4d3g", "my-app", false, true)) ``` -------------------------------- ### Example usage of TraceContext Source: https://pkg.go.dev/github.com/blendle/zapdriver Adding trace context to a log entry. ```go logger.Error("Something happened!", zapdriver.TraceContext("105445aa7843bc8bf206b120001000", "0", true, "my-project-name")...) ``` -------------------------------- ### Quick start HTTP logging Source: https://pkg.go.dev/github.com/blendle/zapdriver The fastest way to log HTTP requests using zapdriver. ```go logger.Info("Request Received.", zapdriver.HTTP(zapdriver.NewHTTP(req, res))) ``` -------------------------------- ### Convenience Operation functions Source: https://pkg.go.dev/github.com/blendle/zapdriver Alternative functions for starting, continuing, or ending an operation. ```go OperationStart(id, producer string) zap.Field OperationCont(id, producer string) zap.Field OperationEnd(id, producer string) zap.Field ``` -------------------------------- ### Get a Zapdriver encoder Source: https://pkg.go.dev/github.com/blendle/zapdriver Use NewProductionEncoderConfig or NewDevelopmentEncoderConfig to retrieve an encoder for custom configuration builds. ```go encoder := zapdriver.NewProductionEncoderConfig() encoder := zapdriver.NewDevelopmentEncoderConfig() ``` -------------------------------- ### func OperationStart Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds a Stackdriver operation field with the given id and producer, indicating the start of an operation. ```APIDOC ## func OperationStart ### Description Adds a Stackdriver operation field with the given id and producer, indicating the start of an operation. ### Signature `func OperationStart(id, producer string) zap.Field` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The operation producer. ### Returns - **zap.Field** - The operation field. ``` -------------------------------- ### func Labels Source: https://pkg.go.dev/github.com/blendle/zapdriver 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. ```APIDOC ## func Labels ### Description 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. ### Signature `func Labels(fields ...zap.Field) zap.Field` ### Parameters - **fields** (...zap.Field) - Required - The Zap fields to filter and wrap. ### Returns - **zap.Field** - The labels namespace field. ``` -------------------------------- ### func ErrorReport Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds the correct Stackdriver "context" field for getting the log line reported as error. ```APIDOC ## func ErrorReport ### Description 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 ### Signature `func ErrorReport(pc uintptr, file string, line int, ok bool) zap.Field` ### Parameters - **pc** (uintptr) - Required - Program counter of the call site. - **file** (string) - Required - File name of the call site. - **line** (int) - Required - Line number of the call site. - **ok** (bool) - Required - Whether the call site information is valid. ### Returns - **zap.Field** - The Stackdriver context field. ``` -------------------------------- ### Initialize Production Logger with Core Source: https://pkg.go.dev/github.com/blendle/zapdriver Use NewProductionWithCore to simplify setting up a logger with Stackdriver Error Reporting enabled. ```go logger, err := zapdriver.NewProductionWithCore(zapdriver.WrapCore( zapdriver.ReportAllErrors(true), zapdriver.ServiceName("my service"), )) ``` -------------------------------- ### OperationStart function Source: https://pkg.go.dev/github.com/blendle/zapdriver Convenience function for the first operation log. ```go func OperationStart(id, producer string) zap.Field ``` -------------------------------- ### Create a configuration struct with zapdriver Source: https://pkg.go.dev/github.com/blendle/zapdriver Use NewProductionConfig or NewDevelopmentConfig to obtain a configuration struct for building a logger. ```go config := zapdriver.NewProductionConfig() config := zapdriver.NewDevelopmentConfig() ``` -------------------------------- ### Initialize Production Encoder Config Source: https://pkg.go.dev/github.com/blendle/zapdriver Use this to manually build a Zap logger configuration with Stackdriver-optimized encoder settings. ```go zapdriver.NewProductionEncoderConfig() ``` -------------------------------- ### func NewDevelopmentConfig Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns a reasonable development logging configuration. ```APIDOC ## func NewDevelopmentConfig ### Description Returns 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. ### Signature `func NewDevelopmentConfig() zap.Config` ### Returns - **zap.Config** - The development configuration. ``` -------------------------------- ### func NewDevelopmentWithCore Source: https://pkg.go.dev/github.com/blendle/zapdriver Same as NewDevelopment but accepts a custom configured core. ```APIDOC ## func NewDevelopmentWithCore ### Description Same as NewDevelopment but accepts a custom configured core. ### Signature `func NewDevelopmentWithCore(core zap.Option, options ...zap.Option) (*zap.Logger, error)` ### Parameters - **core** (zap.Option) - Required - The custom core option. - **options** (...zap.Option) - Optional - Additional options to configure the logger. ### Returns - **(*zap.Logger, error)** - The development logger and an error if any. ``` -------------------------------- ### Create a new Zap logger with zapdriver Source: https://pkg.go.dev/github.com/blendle/zapdriver Use NewProduction or NewDevelopment to initialize a zap.Logger configured for Stackdriver format. ```go logger, err := zapdriver.NewProduction() // with sampling logger, err := zapdriver.NewDevelopment() // with `development` set to `true` ``` -------------------------------- ### func OperationStart Source: https://pkg.go.dev/github.com/blendle/zapdriver OperationStart is a convenience function for `Operation`. It should be called for the first operation log. ```APIDOC ## func OperationStart ### Description OperationStart is a convenience function for `Operation`. It should be called for the first operation log. ### Function Signature ```go func OperationStart(id, producer string) zap.Field ``` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The producer of the operation. ### Returns - **field** (zap.Field) - The zap field representing the operation. ``` -------------------------------- ### NewHTTP constructor Source: https://pkg.go.dev/github.com/blendle/zapdriver Creates a new HTTPPayload instance from standard http.Request and http.Response objects. ```go func NewHTTP(req *http.Request, res *http.Response) *HTTPPayload ``` -------------------------------- ### Manual SourceLocation capture Source: https://pkg.go.dev/github.com/blendle/zapdriver Capturing the stack frame at one location to log it at another. ```go pc, file, line, ok := runtime.Caller(0) // do other stuff... logger.Error("Something happened!", zapdriver.SourceLocation(pc, file, line, ok)) ``` -------------------------------- ### func NewProductionWithCore Source: https://pkg.go.dev/github.com/blendle/zapdriver NewProductionWithCore is same as NewProduction but accepts a custom configured core. ```APIDOC ## func NewProductionWithCore ### Description NewProductionWithCore is same as NewProduction but accepts a custom configured core. ### Function Signature ```go func NewProductionWithCore(core zap.Option, options ...zap.Option) (*zap.Logger, error) ``` ### Parameters - **core** (zap.Option) - Required - The custom configured core. - **options** (zap.Option) - Optional - Additional zap options. ### Returns - **logger** (*zap.Logger) - The constructed logger. - **error** (error) - Any error encountered during construction. ``` -------------------------------- ### Wrap labels in namespace Source: https://pkg.go.dev/github.com/blendle/zapdriver Use Labels to wrap multiple label fields if not using the provided Zap Core. ```go Labels(fields ...zap.Field) zap.Field ``` -------------------------------- ### func NewProductionWithCore Source: https://pkg.go.dev/github.com/blendle/zapdriver Same as NewProduction but accepts a custom configured core. ```APIDOC ## func NewProductionWithCore ### Description Same as NewProduction but accepts a custom configured core. ### Signature `func NewProductionWithCore(core zap.Option, options ...zap.Option) (*zap.Logger, error)` ### Parameters - **core** (zap.Option) - Required - The custom core option. - **options** (...zap.Option) - Optional - Additional options to configure the logger. ### Returns - **(*zap.Logger, error)** - The production logger and an error if any. ``` -------------------------------- ### func NewProductionConfig Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns a reasonable production logging configuration. ```APIDOC ## func NewProductionConfig ### Description Returns 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. ### Signature `func NewProductionConfig() zap.Config` ### Returns - **zap.Config** - The production configuration. ``` -------------------------------- ### NewProductionWithCore function Source: https://pkg.go.dev/github.com/blendle/zapdriver Creates a new production logger with a custom configured core. ```go func NewProductionWithCore(core zap.Option, options ...zap.Option) (*zap.Logger, error) ``` -------------------------------- ### Define Label logging field Source: https://pkg.go.dev/github.com/blendle/zapdriver Creates a label field that sets the key to labels.. ```go Label(key, value string) zap.Field ``` -------------------------------- ### Manually build HTTP payload Source: https://pkg.go.dev/github.com/blendle/zapdriver Construct the HTTPPayload struct manually for logging. ```go req := &HTTPPayload{ RequestMethod: "GET", RequestURL: "/", Status: 200, } ``` -------------------------------- ### OperationCont function Source: https://pkg.go.dev/github.com/blendle/zapdriver Convenience function for non-start/end operation logs. ```go func OperationCont(id, producer string) zap.Field ``` -------------------------------- ### SourceLocation function Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds the Stackdriver SourceLocation field. ```go func SourceLocation(pc uintptr, file string, line int, ok bool) zap.Field ``` -------------------------------- ### func NewDevelopment Source: https://pkg.go.dev/github.com/blendle/zapdriver Builds a development Logger that writes DebugLevel and above logs to standard error in a human-friendly format. ```APIDOC ## func NewDevelopment ### Description 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). ### Signature `func NewDevelopment(options ...zap.Option) (*zap.Logger, error)` ### Parameters - **options** (...zap.Option) - Optional - Additional options to configure the logger. ### Returns - **(*zap.Logger, error)** - The development logger and an error if any. ``` -------------------------------- ### MarshalLogObject implementation Source: https://pkg.go.dev/github.com/blendle/zapdriver Implements the zapcore.ObjectMarshaller interface for HTTPPayload. ```go func (req HTTPPayload) MarshalLogObject(enc zapcore.ObjectEncoder) error ``` -------------------------------- ### MarshalLogObject Source: https://pkg.go.dev/github.com/blendle/zapdriver Implements the zapcore.ObjectMarshaller interface for HTTPPayload, enabling structured logging. ```APIDOC ## MarshalLogObject ### Description MarshalLogObject implements the zapcore.ObjectMarshaller interface, allowing HTTPPayload to be logged with zap. ### Method func ### Endpoint MarshalLogObject(enc zapcore.ObjectEncoder) error ### Parameters #### Parameters - **enc** (zapcore.ObjectEncoder) - Required - The object encoder used to write the payload fields. ### Response #### Success Response - **error** (error) - Returns nil on success, or an error if encoding fails. ### Response Example ```go err := payload.MarshalLogObject(encoder) ``` ``` -------------------------------- ### func HTTP Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds the correct Stackdriver "HTTP" field. ```APIDOC ## func HTTP ### Description Adds the correct Stackdriver "HTTP" field. See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest ### Signature `func HTTP(req *HTTPPayload) zap.Field` ### Parameters - **req** (*HTTPPayload) - Required - The HTTP payload to add as a field. ### Returns - **zap.Field** - The Stackdriver HTTP field. ``` -------------------------------- ### ServiceName function Source: https://pkg.go.dev/github.com/blendle/zapdriver Core option to add ServiceContext() to all logs with a specified service name. ```go func ServiceName(name string) func(*core) ``` -------------------------------- ### NewHTTP Source: https://pkg.go.dev/github.com/blendle/zapdriver Constructs a new HTTPPayload struct from an HTTP request and response. ```APIDOC ## NewHTTP ### Description NewHTTP returns a new HTTPPayload struct, based on the passed in http.Request and http.Response objects. ### Method func ### Endpoint NewHTTP(req *http.Request, res *http.Response) *HTTPPayload ### Parameters #### Parameters - **req** (*http.Request) - Required - The HTTP request object. - **res** (*http.Response) - Required - The HTTP response object. ### Response #### Success Response - **HTTPPayload** (*HTTPPayload) - The constructed HTTPPayload struct. ### Response Example ```go payload := NewHTTP(req, res) ``` ``` -------------------------------- ### func NewProduction Source: https://pkg.go.dev/github.com/blendle/zapdriver Builds a sensible production Logger that writes InfoLevel and above logs to standard error as JSON. ```APIDOC ## func NewProduction ### Description Builds a sensible production Logger that writes InfoLevel and above logs to standard error as JSON. It's a shortcut for NewProductionConfig().Build(...Option). ### Signature `func NewProduction(options ...zap.Option) (*zap.Logger, error)` ### Parameters - **options** (...zap.Option) - Optional - Additional options to configure the logger. ### Returns - **(*zap.Logger, error)** - The production logger and an error if any. ``` -------------------------------- ### WrapCore function Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns a zap.Option that wraps the default core with the zapdriver one. ```go func WrapCore(options ...func(*core)) zap.Option ``` -------------------------------- ### TraceContext function Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds Stackdriver trace, span, and trace_sampled fields. ```go func TraceContext(trace string, spanId string, sampled bool, projectName string) []zap.Field ``` -------------------------------- ### func NewDevelopmentEncoderConfig Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns an opinionated EncoderConfig for development environments. ```APIDOC ## func NewDevelopmentEncoderConfig ### Description Returns an opinionated EncoderConfig for development environments. ### Signature `func NewDevelopmentEncoderConfig() zapcore.EncoderConfig` ### Returns - **zapcore.EncoderConfig** - The development encoder configuration. ``` -------------------------------- ### OperationEnd function Source: https://pkg.go.dev/github.com/blendle/zapdriver Convenience function for the last operation log. ```go func OperationEnd(id, producer string) zap.Field ``` -------------------------------- ### Define SourceLocation logging field Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds source code location information to log lines. ```go SourceLocation(pc uintptr, file string, line int, ok bool) zap.Field ``` -------------------------------- ### ServiceContext function Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds service information required for error reporting. ```go func ServiceContext(name string) zap.Field ``` -------------------------------- ### Configure Custom Logger with Error Reporting Source: https://pkg.go.dev/github.com/blendle/zapdriver Configure a custom Zap logger to report errors to Stackdriver by wrapping the core with error reporting options. ```go config := &zap.Config{} logger, err := config.Build(zapdriver.WrapCore( zapdriver.ReportAllErrors(true), zapdriver.ServiceName("my service"), )) ``` -------------------------------- ### Automatic SourceLocation capture Source: https://pkg.go.dev/github.com/blendle/zapdriver Adding source location at the frame of the triggered log line without using zapdriver.Core. ```go logger.Error("Something happened!", zapdriver.SourceLocation(runtime.Caller(0))) ``` -------------------------------- ### Define TraceContext logging field Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds trace context information to log lines. ```go TraceContext(trace string, spanId string, sampled bool, projectName string) []zap.Field ``` -------------------------------- ### HTTPPayload struct definition Source: https://pkg.go.dev/github.com/blendle/zapdriver Defines the structure for HTTP request data compatible with Stackdriver logging. ```go 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"` } ``` -------------------------------- ### func SourceLocation Source: https://pkg.go.dev/github.com/blendle/zapdriver SourceLocation adds the correct Stackdriver "SourceLocation" field. ```APIDOC ## func SourceLocation ### Description SourceLocation adds the correct Stackdriver "SourceLocation" field. ### Function Signature ```go func SourceLocation(pc uintptr, file string, line int, ok bool) zap.Field ``` ### Parameters - **pc** (uintptr) - Required - The program counter. - **file** (string) - Required - The file name. - **line** (int) - Required - The line number. - **ok** (bool) - Required - Whether the location is valid. ### Returns - **field** (zap.Field) - The zap field representing the source location. ``` -------------------------------- ### func NewProductionEncoderConfig Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns an opinionated EncoderConfig for production environments. ```APIDOC ## func NewProductionEncoderConfig ### Description Returns an opinionated EncoderConfig for production environments. ### Signature `func NewProductionEncoderConfig() zapcore.EncoderConfig` ### Returns - **zapcore.EncoderConfig** - The production encoder configuration. ``` -------------------------------- ### Attach Service Context for Error Reporting Source: https://pkg.go.dev/github.com/blendle/zapdriver Ensure error reports are correctly attributed by attaching a ServiceContext to the log entry or the logger instance. ```go logger.Error( "An error to be reported!", zapdriver.ErrorReport(runtime.Caller(0)), zapdriver.ServiceContext("my service"), ) // Or permanently attach it to your logger logger = logger.With(zapdriver.ServiceContext("my service")) // and then use it logger.Error("An error to be reported!", zapdriver.ErrorReport(runtime.Caller(0))) ``` -------------------------------- ### Auto-generate HTTP payload Source: https://pkg.go.dev/github.com/blendle/zapdriver Use NewHTTP to generate the payload from existing request and response objects. ```go NewHTTP(req *http.Request, res *http.Response) *HTTPPayload ``` -------------------------------- ### Inject Zapdriver Core Source: https://pkg.go.dev/github.com/blendle/zapdriver Inject the custom Zapdriver core into a standard Zap configuration to enable automatic label rewriting and source location tracking. ```go config := &zap.Config{} logger, err := config.Build(zapdriver.WrapCore()) ``` -------------------------------- ### func WrapCore Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns a zap.Option that wraps the core with the given options. ```APIDOC ## func WrapCore ### Description Returns a zap.Option that wraps the core with the given options. ### Signature `func WrapCore(options ...func(*core)) zap.Option` ### Parameters - **options** (...func(*core)) - Required - The core options to apply. ### Returns - **zap.Option** - The option that wraps the core. ``` -------------------------------- ### func WrapCore Source: https://pkg.go.dev/github.com/blendle/zapdriver WrapCore returns a `zap.Option` that wraps the default core with the zapdriver one. ```APIDOC ## func WrapCore ### Description WrapCore returns a `zap.Option` that wraps the default core with the zapdriver one. ### Function Signature ```go func WrapCore(options ...func(*core)) zap.Option ``` ### Parameters - **options** (func(*core)) - Optional - Core options to apply. ### Returns - **option** (zap.Option) - The zap option that wraps the core. ``` -------------------------------- ### func Label Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds an optional label to the payload. ```APIDOC ## func Label ### Description 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" }. ### Signature `func Label(key, value string) zap.Field` ### Parameters - **key** (string) - Required - The label key. - **value** (string) - Required - The label value. ### Returns - **zap.Field** - The label field. ``` -------------------------------- ### Define HTTP logging field Source: https://pkg.go.dev/github.com/blendle/zapdriver The HTTP function creates a zap field for logging request/response cycles. ```go HTTP(req *HTTPPayload) zap.Field ``` -------------------------------- ### Define Operation logging field Source: https://pkg.go.dev/github.com/blendle/zapdriver Groups log lines into a single operation. ```go Operation(id, producer string, first, last bool) zap.Field ``` -------------------------------- ### func ServiceName Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns a function that sets the service name on the core. ```APIDOC ## func ServiceName ### Description Returns a function that sets the service name on the core. ### Signature `func ServiceName(name string) func(*core)` ### Parameters - **name** (string) - Required - The service name. ### Returns - **func(*core)** - A function that sets the service name on the core. ``` -------------------------------- ### func OperationCont Source: https://pkg.go.dev/github.com/blendle/zapdriver OperationCont is a convenience function for `Operation`. It should be called for any non-start/end operation log. ```APIDOC ## func OperationCont ### Description OperationCont is a convenience function for `Operation`. It should be called for any non-start/end operation log. ### Function Signature ```go func OperationCont(id, producer string) zap.Field ``` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The producer of the operation. ### Returns - **field** (zap.Field) - The zap field representing the operation. ``` -------------------------------- ### Operation function Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds the Stackdriver operation field for long-running operations. ```go func Operation(id, producer string, first, last bool) zap.Field ``` -------------------------------- ### func Operation Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds a Stackdriver operation field with the given id and producer, and sets the first and last flags. ```APIDOC ## func Operation ### Description Adds a Stackdriver operation field with the given id and producer, and sets the first and last flags. ### Signature `func Operation(id, producer string, first, last bool) zap.Field` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The operation producer. - **first** (bool) - Required - Whether this is the first operation. - **last** (bool) - Required - Whether this is the last operation. ### Returns - **zap.Field** - The operation field. ``` -------------------------------- ### func SourceLocation Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds a Stackdriver source location field with the given program counter, file, line, and validity flag. ```APIDOC ## func SourceLocation ### Description Adds a Stackdriver source location field with the given program counter, file, line, and validity flag. ### Signature `func SourceLocation(pc uintptr, file string, line int, ok bool) zap.Field` ### Parameters - **pc** (uintptr) - Required - Program counter of the call site. - **file** (string) - Required - File name of the call site. - **line** (int) - Required - Line number of the call site. - **ok** (bool) - Required - Whether the call site information is valid. ### Returns - **zap.Field** - The source location field. ``` -------------------------------- ### Report Errors Manually Source: https://pkg.go.dev/github.com/blendle/zapdriver Attach ErrorReport to specific log calls to manually trigger error reporting for individual events. ```go logger.Error("An error to be reported!", zapdriver.ErrorReport(runtime.Caller(0))) // Or get Caller details pc, file, line, ok := runtime.Caller(0) // do other stuff... and log elsewhere logger.Error("Another error to be reported!", zapdriver.ErrorReport(pc, file, line, ok)) ``` -------------------------------- ### RFC3339NanoTimeEncoder function Source: https://pkg.go.dev/github.com/blendle/zapdriver Serializes time.Time to an RFC3339Nano-formatted string with nanoseconds precision. ```go func RFC3339NanoTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) ``` -------------------------------- ### func TraceContext Source: https://pkg.go.dev/github.com/blendle/zapdriver TraceContext adds the correct Stackdriver "trace", "span", "trace_sampled" fields. ```APIDOC ## func TraceContext ### Description TraceContext adds the correct Stackdriver "trace", "span", "trace_sampled" fields. ### Function Signature ```go func TraceContext(trace string, spanId string, sampled bool, projectName string) []zap.Field ``` ### Parameters - **trace** (string) - Required - The trace ID. - **spanId** (string) - Required - The span ID. - **sampled** (bool) - Required - Whether the trace is sampled. - **projectName** (string) - Required - The project name. ### Returns - **fields** ([]zap.Field) - The zap fields representing the trace context. ``` -------------------------------- ### func ServiceName Source: https://pkg.go.dev/github.com/blendle/zapdriver zapdriver core option to add `ServiceContext()` to all logs with `name` as service name. ```APIDOC ## func ServiceName ### Description zapdriver core option to add `ServiceContext()` to all logs with `name` as service name. ### Function Signature ```go func ServiceName(name string) func(*core) ``` ### Parameters - **name** (string) - Required - The service name. ``` -------------------------------- ### func Operation Source: https://pkg.go.dev/github.com/blendle/zapdriver Operation adds the correct Stackdriver "operation" field. Additional information about a potentially long-running operation with which a log entry is associated. ```APIDOC ## func Operation ### Description Operation adds the correct Stackdriver "operation" field. Additional information about a potentially long-running operation with which a log entry is associated. ### Function Signature ```go func Operation(id, producer string, first, last bool) zap.Field ``` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The producer of the operation. - **first** (bool) - Required - Whether this is the first log entry in the operation. - **last** (bool) - Required - Whether this is the last log entry in the operation. ### Returns - **field** (zap.Field) - The zap field representing the operation. ``` -------------------------------- ### func OperationEnd Source: https://pkg.go.dev/github.com/blendle/zapdriver OperationEnd is a convenience function for `Operation`. It should be called for the last operation log. ```APIDOC ## func OperationEnd ### Description OperationEnd is a convenience function for `Operation`. It should be called for the last operation log. ### Function Signature ```go func OperationEnd(id, producer string) zap.Field ``` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The producer of the operation. ### Returns - **field** (zap.Field) - The zap field representing the operation. ``` -------------------------------- ### ReportAllErrors function Source: https://pkg.go.dev/github.com/blendle/zapdriver Core option to report logs with level error or above to Stackdriver using ErrorReport(). ```go func ReportAllErrors(report bool) func(*core) ``` -------------------------------- ### type HTTPPayload Source: https://pkg.go.dev/github.com/blendle/zapdriver HTTPPayload is a struct that represents an HTTP request/response payload for Stackdriver logging. ```APIDOC ## type HTTPPayload ### Description HTTPPayload is a struct that represents an HTTP request/response payload for Stackdriver logging. ### Definition `type HTTPPayload struct { ... }` ### Methods #### func NewHTTP Creates a new HTTPPayload from an HTTP request and response. `func NewHTTP(req *http.Request, res *http.Response) *HTTPPayload` #### func (req HTTPPayload) MarshalLogObject Implements zapcore.ObjectMarshaler to marshal the HTTP payload. `func (req HTTPPayload) MarshalLogObject(enc zapcore.ObjectEncoder) error` ``` -------------------------------- ### func OperationCont Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds a Stackdriver operation field with the given id and producer, indicating a continuation operation. ```APIDOC ## func OperationCont ### Description Adds a Stackdriver operation field with the given id and producer, indicating a continuation operation. ### Signature `func OperationCont(id, producer string) zap.Field` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The operation producer. ### Returns - **zap.Field** - The operation field. ``` -------------------------------- ### func TraceContext Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds Stackdriver trace context fields with the given trace ID, span ID, sampled flag, and project name. ```APIDOC ## func TraceContext ### Description Adds Stackdriver trace context fields with the given trace ID, span ID, sampled flag, and project name. ### Signature `func TraceContext(trace string, spanId string, sampled bool, projectName string) []zap.Field` ### Parameters - **trace** (string) - Required - The trace ID. - **spanId** (string) - Required - The span ID. - **sampled** (bool) - Required - Whether the trace is sampled. - **projectName** (string) - Required - The project name. ### Returns - **[]zap.Field** - The trace context fields. ``` -------------------------------- ### func EncodeLevel Source: https://pkg.go.dev/github.com/blendle/zapdriver Maps the internal Zap log level to the appropriate Stackdriver level. ```APIDOC ## func EncodeLevel ### Description Maps the internal Zap log level to the appropriate Stackdriver level. ### Signature `func EncodeLevel(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)` ### Parameters - **l** (zapcore.Level) - Required - The internal Zap log level to map. - **enc** (zapcore.PrimitiveArrayEncoder) - Required - The encoder to write the mapped level to. ``` -------------------------------- ### func ServiceContext Source: https://pkg.go.dev/github.com/blendle/zapdriver ServiceContext adds the correct service information adding the log line. It is a required field if an error needs to be reported. ```APIDOC ## func ServiceContext ### Description ServiceContext adds the correct service information adding the log line. It is a required field if an error needs to be reported. ### Function Signature ```go func ServiceContext(name string) zap.Field ``` ### Parameters - **name** (string) - Required - The service name. ### Returns - **field** (zap.Field) - The zap field representing the service context. ``` -------------------------------- ### func ReportAllErrors Source: https://pkg.go.dev/github.com/blendle/zapdriver Returns a function that sets whether to report all errors on the core. ```APIDOC ## func ReportAllErrors ### Description Returns a function that sets whether to report all errors on the core. ### Signature `func ReportAllErrors(report bool) func(*core)` ### Parameters - **report** (bool) - Required - Whether to report all errors. ### Returns - **func(*core)** - A function that sets the report flag on the core. ``` -------------------------------- ### func ReportAllErrors Source: https://pkg.go.dev/github.com/blendle/zapdriver zapdriver core option to report all logs with level error or above to stackdriver using `ErrorReport()` when set to true. ```APIDOC ## func ReportAllErrors ### Description zapdriver core option to report all logs with level error or above to stackdriver using `ErrorReport()` when set to true. ### Function Signature ```go func ReportAllErrors(report bool) func(*core) ``` ### Parameters - **report** (bool) - Required - Whether to report all error-level logs. ``` -------------------------------- ### func OperationEnd Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds a Stackdriver operation field with the given id and producer, indicating the end of an operation. ```APIDOC ## func OperationEnd ### Description Adds a Stackdriver operation field with the given id and producer, indicating the end of an operation. ### Signature `func OperationEnd(id, producer string) zap.Field` ### Parameters - **id** (string) - Required - The operation ID. - **producer** (string) - Required - The operation producer. ### Returns - **zap.Field** - The operation field. ``` -------------------------------- ### func ServiceContext Source: https://pkg.go.dev/github.com/blendle/zapdriver Adds a Stackdriver service context field with the given service name. ```APIDOC ## func ServiceContext ### Description Adds a Stackdriver service context field with the given service name. ### Signature `func ServiceContext(name string) zap.Field` ### Parameters - **name** (string) - Required - The service name. ### Returns - **zap.Field** - The service context field. ``` -------------------------------- ### func RFC3339NanoTimeEncoder Source: https://pkg.go.dev/github.com/blendle/zapdriver Encodes a time.Time in RFC3339Nano format. ```APIDOC ## func RFC3339NanoTimeEncoder ### Description Encodes a time.Time in RFC3339Nano format. ### Signature `func RFC3339NanoTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)` ### Parameters - **t** (time.Time) - Required - The time to encode. - **enc** (zapcore.PrimitiveArrayEncoder) - Required - The encoder to write the time to. ``` -------------------------------- ### func RFC3339NanoTimeEncoder Source: https://pkg.go.dev/github.com/blendle/zapdriver RFC3339NanoTimeEncoder serializes a time.Time to an RFC3339Nano-formatted string with nanoseconds precision. ```APIDOC ## func RFC3339NanoTimeEncoder ### Description RFC3339NanoTimeEncoder serializes a time.Time to an RFC3339Nano-formatted string with nanoseconds precision. ### Function Signature ```go func RFC3339NanoTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) ``` ### Parameters - **t** (time.Time) - Required - The time to serialize. - **enc** (zapcore.PrimitiveArrayEncoder) - Required - The encoder to write the serialized time to. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.