slogxgooglecloudlogging

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 10 Imported by: 0

README

Google Cloud logo

go-slogx-googlecloudlogging

Handler for the `go.innotegrity.dev/slogx` package which enables logging with Google Cloud Logging.






Table of Contents

👁️ Overview

go-slogx-googlecloudlogging is a handler for the go.innotegrity.dev/slogx package. It allows you to use the slogx or log/slog library to log messages via Google Cloud Logging.

Please review the module documentation for details on how to properly the functions and classes contained in this module.

✅ Requirements

This module is supported for Go v1.21 and later.

📃 License

This module is distributed under the MIT License.

❓ Questions, Issues and Feature Requests

If you have questions about this project, find a bug or wish to submit a feature request, please submit an issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGoogleCloudLoggingHandlerLevelMapper

func DefaultGoogleCloudLoggingHandlerLevelMapper(level slog.Leveler) logging.Severity

DefaultGoogleCloudLoggingHandlerLevelMapper is a default function for mapping slog levels to GCP logging levels.

func NewGoogleCloudLoggingHandler

func NewGoogleCloudLoggingHandler(opts GoogleCloudLoggingHandlerOptions) (*googleCloudLoggingHandler, error)

NewGoogleCloudLoggingHandler creates a new handler object.

Types

type GoogleCloudLoggingHandlerOptions

type GoogleCloudLoggingHandlerOptions struct {
	// ClientOptions is a list of options for the Google Cloud Logging client.
	ClientOptions []option.ClientOption

	// EnableAsync will execute the Handle() function in a separate goroutine.
	//
	// When async is enabled, you should be sure to call the Shutdown() function or use the slogx.Shutdown()
	// function to ensure all goroutines are finished and any pending records have been written.
	EnableAsync bool

	// Level is the minimum log level to write to the handler.
	//
	// By default, the level will be set to slog.LevelInfo if not supplied.
	Level slog.Leveler

	// LevelMapper is a function to use to map an slog.Leveler level to the corresponding Google Cloud Logging severity.
	//
	// If nil, the default mapper will be used, which should be fine for most cases.
	LevelMapper func(slog.Leveler) logging.Severity

	// LoggerOptions is a list of options to pass to the Google Cloud Logging client's underlying logger.
	LoggerOptions []logging.LoggerOption

	// LogName is the name of the log to use when logging messages.
	//
	// This option is required.
	LogName string

	// ProjectID is the ID of the GCP project to which the logger belongs.
	//
	// This option is required.
	ProjectID string

	// RecordFormatter specifies the formatter to use to format the record before sending it to the GCP logger.
	//
	// You should always be sure to format the buffer into a proper JSON payload.
	//
	// If no formatter is supplied, formatter.DefaultJSONFormatter is used to format the output.
	RecordFormatter formatter.BufferFormatter
}

GoogleCloudLoggingHandlerOptions holds the options for the JSON handler.

func DefaultGoogleCloudLoggingHandlerOptions added in v0.2.0

func DefaultGoogleCloudLoggingHandlerOptions() GoogleCloudLoggingHandlerOptions

DefaultGoogleCloudLoggingHandlerOptions returns a default set of options for the handler.

func GetGoogleCloudLoggingHandlerOptionsFromContext added in v0.2.0

func GetGoogleCloudLoggingHandlerOptionsFromContext(ctx context.Context) *GoogleCloudLoggingHandlerOptions

GetGoogleCloudLoggingHandlerOptionsFromContext retrieves the options from the context.

If the options are not set in the context, a set of default options is returned instead.

func (*GoogleCloudLoggingHandlerOptions) AddToContext added in v0.2.0

AddToContext adds the options to the given context and returns the new context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL