sinit

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 17 Imported by: 0

README

sinit

Common log config and initialization

For a full example run:

export SPLUNK_URL=xxx
export SPLUNK_TOKEN=xxx
export AWS_REGION=xxx
export AWS_SECRET=xxx
export AWS_KEY=xxx
export SENTRY_DSN=xxx
go run github.com/osbuild/logging/internal/example_sinit/

Documentation

Overview

Common log configuration, initialization and flushing functions for osbuild projects.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidURL = errors.New("invalid URL")
View Source
var ErrSentryInitialization = errors.New("sentry initialization error")

Functions

func Flush

func Flush()

Flush flushes all pending logs to the configured outputs. Blocks until all logs are written.

func InitializeLogging

func InitializeLogging(ctx context.Context, config LoggingConfig) error

InitializeLogging initializes the logging system with the provided configuration. Use Flush to ensure all logs are written before exiting. Subsequent calls to InitializeLogging will have no effect and will not return any error.

func StdLogger

func StdLogger() *log.Logger

StdLogger returns a standard library legacy logger that writes to configured outputs. This is only useful for passing to libraries that require a legacy Go standard logger.

Types

type CloudWatchConfig

type CloudWatchConfig struct {
	// Enabled is a flag to enable this output.
	Enabled bool

	// Logging level for this output. Strings "debug", "info", "warn", "error", "fatal", "panic" are accepted.
	// Keep in mind that log/slog has only 4 levels: Debug, Info, Warn, Error. Default value is "debug".
	Level string

	// AWSRegion is the AWS region.
	AWSRegion string

	// AWSKey is the AWS access key.
	AWSKey string

	// AWSSecret is the AWS secret key.
	AWSSecret string

	// AWSSession is an optional AWS session token.
	AWSSession string

	// AWSLogGroup is the AWS CloudWatch log group.
	AWSLogGroup string

	// AWSLogStream is the AWS CloudWatch log stream.
	AWSLogStream string
}

CloudWatchConfig is the configuration for the CloudWatch output.

type JournalConfig

type JournalConfig struct {
	// Enabled is a flag to enable this output.
	Enabled bool

	// Logging level for this output. Strings "debug", "info", "warn", "error", "fatal", "panic" are accepted.
	// Keep in mind that log/slog has only 4 levels: Debug, Info, Warn, Error. Default value is "debug".
	Level string
}

JournalConfig is the configuration for the system journal.

type LoggingConfig

type LoggingConfig struct {
	StdoutConfig StdoutConfig

	JournalConfig JournalConfig

	SplunkConfig SplunkConfig

	CloudWatchConfig CloudWatchConfig

	SentryConfig SentryConfig

	TracingConfig TracingConfig
}

LoggingConfig is the configuration for the logging system.

type SentryConfig

type SentryConfig struct {
	// Enabled is a flag to enable Sentry.
	Enabled bool

	// DSN is the Sentry DSN.
	DSN string
}

SentryConfig is the configuration for the Sentry output. Only log entries with error level are sent to Sentry.

type SplunkConfig

type SplunkConfig struct {
	// Enabled is a flag to enable this output.
	Enabled bool

	// Logging level for this output. Strings "debug", "info", "warn", "error", "fatal", "panic" are accepted.
	// Keep in mind that log/slog has only 4 levels: Debug, Info, Warn, Error. Default value is "debug".
	Level string

	// URL is the Splunk HEC URL.
	URL string

	// Token is the Splunk HEC token.
	Token string

	// Source is the Splunk HEC source.
	Source string

	// Hostname is the Splunk HEC hostname.
	Hostname string
}

SplunkConfig is the configuration for the Splunk output.

type StdoutConfig

type StdoutConfig struct {
	// Enabled is a flag to enable this output.
	Enabled bool

	// Logging level for this output. Strings "debug", "info", "warn", "error", "fatal", "panic" are accepted.
	// Keep in mind that log/slog has only 4 levels: Debug, Info, Warn, Error. Default value is "debug".
	Level string

	// Format is the log format to use for stdout logging. Possible values are "json" and "text".
	Format string
}

StdoutConfig is the configuration for the standard output.

type TracingConfig

type TracingConfig struct {
	// Enabled is a flag to enable tracing
	Enabled bool

	// CustomAttrs is a list of custom static attributes to add to every log entry. To add
	// dynamic attributes, use ContextCallback that can access context.
	CustomAttrs []slog.Attr

	// ContextCallback is an optional callback function that is called for each log entry
	// to add additional attributes to the log entry.
	ContextCallback strc.MultiCallback
}

TracingConfig is the configuration for strc.

Jump to

Keyboard shortcuts

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