Documentation
¶
Overview ¶
Package log contains the CloudNativePG logging infrastructure
Package log contains the logging subsystem of the instance manager
Index ¶
- Constants
- func Debug(msg string, keysAndValues ...interface{})
- func Enabled() bool
- func Error(err error, msg string, keysAndValues ...interface{})
- func ForwardToOpenTelemetry(line []byte)
- func GetFieldsRemapFlags() (res []string)
- func Info(msg string, keysAndValues ...interface{})
- func IntoContext(ctx context.Context, log Logger) context.Context
- func SetLogLevel(level string)
- func SetLogger(logr logr.Logger)
- func SetTruncateDestination(truncate bool)
- func ShutdownOpenTelemetry(ctx context.Context) error
- func Trace(msg string, keysAndValues ...interface{})
- func Warning(msg string, keysAndValues ...interface{})
- type ConfigureOption
- type Flags
- type Logger
Constants ¶
const ( // ErrorLevelString is the string representation of the error level ErrorLevelString = "error" // ErrorLevel is the error level priority ErrorLevel = zapcore.ErrorLevel // InfoLevelString is the string representation of the info level InfoLevelString = "info" // InfoLevel is the info level priority InfoLevel = zapcore.InfoLevel // DebugLevelString is the string representation of the debug level DebugLevelString = "debug" // DebugLevel is the debug level priority DebugLevel zapcore.Level = -2 // TraceLevelString is the string representation of the trace level TraceLevelString = "trace" // TraceLevel is the trace level priority TraceLevel zapcore.Level = -4 // WarningLevelString is the string representation of the warning level WarningLevelString = "warning" // WarningLevel is the warning level priority WarningLevel = zapcore.WarnLevel // DefaultLevelString is the string representation of the default level DefaultLevelString = InfoLevelString // DefaultLevel is the default logging level DefaultLevel = InfoLevel )
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(msg string, keysAndValues ...interface{})
Debug exposes the same method from the logr.Logger interface using the default logger
func Enabled ¶
func Enabled() bool
Enabled exposes the same method from the logr.Logger interface using the default logger
func ForwardToOpenTelemetry ¶ added in v0.7.0
func ForwardToOpenTelemetry(line []byte)
ForwardToOpenTelemetry exports, without writing it on the log destination, a record that another process wrote in JSON, such as a process spawned by this one whose output is already written there. The process is expected to use the same time and level keys as this one, as set by GetFieldsRemapFlags. The record keeps its time, level, logger name and fields, while a line that is not a JSON object is exported as an info message. The line is parsed whole and queued as is, so the caller bounds its size. Records below the configured level are dropped, and times must be RFC3339. The process must not export on its own, or its records are exported twice. It is a no-op when the OpenTelemetry export is disabled.
func GetFieldsRemapFlags ¶
func GetFieldsRemapFlags() (res []string)
GetFieldsRemapFlags returns the required flags to set the logging fields
func Info ¶
func Info(msg string, keysAndValues ...interface{})
Info exposes the same method from the logr.Logger interface using the default logger
func IntoContext ¶
IntoContext injects a logger into a context
func SetTruncateDestination ¶ added in v0.6.0
func SetTruncateDestination(truncate bool)
SetTruncateDestination controls whether the log destination, when it is a regular file, is truncated on open instead of appended to. This has no effect when the destination is a FIFO.
func ShutdownOpenTelemetry ¶ added in v0.7.0
ShutdownOpenTelemetry exports the log records that are still queued and stops the OpenTelemetry export, whose later records are only written to the log destination. It is a no-op when the export is disabled or already stopped, or when the provider was passed with WithOpenTelemetryLoggerProvider.
Types ¶
type ConfigureOption ¶ added in v0.6.0
type ConfigureOption func(*configureOptions)
ConfigureOption customizes the behavior of ConfigureLogging
func WithDisabledSampling ¶ added in v0.6.0
func WithDisabledSampling() ConfigureOption
WithDisabledSampling turns off the duplicate-message sampler that the controller-runtime zap builder installs on production-mode loggers, which passes only the first 100 messages sharing the same (level, message) pair each second and roughly 1 in 100 afterwards. Use it for processes whose output must be complete, such as the instance manager forwarding the PostgreSQL log stream.
func WithOpenTelemetry ¶ added in v0.7.0
func WithOpenTelemetry() ConfigureOption
WithOpenTelemetry also exports the log records to an OpenTelemetry collector via OTLP, when the OTEL_EXPORTER_OTLP_ENDPOINT or the OTEL_EXPORTER_OTLP_LOGS_ENDPOINT environment variable is set, unless OTEL_LOGS_EXPORTER is "none" or OTEL_SDK_DISABLED is "true". The exporter is configured with the standard OTEL_EXPORTER_OTLP_* variables, and OTEL_EXPORTER_OTLP_LOGS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL selects between "http/protobuf", the default, and "grpc". The records are exported at the configured log level, in the background: when the collector cannot keep up, they are dropped instead of blocking the caller. Call ShutdownOpenTelemetry before the process exits. Configure the logging once: a later call replaces the export without stopping the previous one, and is not safe to run while records are being forwarded.
It also replaces the global error handler of OpenTelemetry, which covers all its signals, with one that writes the errors only to the log destination. A caller that wants its own handler sets it after ConfigureLogging, and must not log through this package.
func WithOpenTelemetryLoggerProvider ¶ added in v0.7.0
func WithOpenTelemetryLoggerProvider(provider otellog.LoggerProvider) ConfigureOption
WithOpenTelemetryLoggerProvider also exports the log records through the given provider, whatever the environment, for a process that configures OpenTelemetry for its other signals and wants the log records to share their resource and exporter selection. The records are exported at the configured log level. The caller owns the provider and shuts it down before the process exits, as ShutdownOpenTelemetry ignores it. This option takes precedence over WithOpenTelemetry, and replaces the global error handler of OpenTelemetry in the same way.
type Flags ¶
type Flags struct {
// contains filtered or unexported fields
}
Flags contains the set of values necessary for configuring the manager
func (*Flags) ConfigureLogging ¶
func (l *Flags) ConfigureLogging(opts ...ConfigureOption)
ConfigureLogging configure the logging honoring the flags passed from the user This is executed after args were already parsed.
type Logger ¶
type Logger interface {
Enabled() bool
Error(err error, msg string, keysAndValues ...interface{})
Warning(msg string, keysAndValues ...interface{})
Info(msg string, keysAndValues ...interface{})
Debug(msg string, keysAndValues ...interface{})
Trace(msg string, keysAndValues ...interface{})
WithCaller() Logger
WithValues(keysAndValues ...interface{}) Logger
WithName(name string) Logger
GetLogger() logr.Logger
}
Logger is a reduced version of logr.Logger
func FromContext ¶
FromContext builds a logger with some additional information stored in the context
func SetupLogger ¶
SetupLogger sets up the logger from a given context, wrapping it with a new uuid, and any given name
func WithCaller ¶
func WithCaller() Logger
WithCaller exposes the same method from logr.Logger interface using the default logger
func WithName ¶
WithName exposes the same method from the logr.Logger interface using the default logger
func WithValues ¶
func WithValues(keysAndValues ...interface{}) Logger
WithValues exposes the same method from the logr.Logger interface using the default logger