fallbacklog

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package fallbacklog implements a fallback logger.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrCodeFilePathMalformed = errors.New("unexpected source filepath")

ErrCodeFilePathMalformed reports that the code file path is malformed.

Functions

func Error

func Error(err error)

Error logs err using a fallback logger. This function should only be used when no instrumented logger is available, that is, when an unrecoverable error occurs. It tries to mimic OpenTelemetry structure a bit, however it is nowhere close to follow its conventions. Its sole purpose is to be a last resort logger.

Example
package main

import (
	"errors"

	"codeberg.org/kema/kmicro/pkg/fallbacklog"
)

var ErrExample = errors.New("example") // ErrExample reports an example error.

func main() {
	run := func() error {
		return ErrExample
	}

	err := run()
	if err != nil {
		fallbacklog.Error(err)
	}
}

func Info

func Info(msg string, attrs ...slog.Attr)

Info logs msg with attrs using a fallback logger. This function should only be used when no instrumented logger is available, or when if is desired to log to stdout instead of OTLP. It tries to mimic OpenTelemetry structure a bit, however it is nowhere close to follow its conventions. Its sole purpose is to be a last resort logger.

Types

type OtelErrorHandler

type OtelErrorHandler struct {
	Exporter *StdoutExporter // Exporter represents the log exporter that is used by the handler.
}

OtelErrorHandler represents an OpenTelemetry logger for internal SDK errors.

func (*OtelErrorHandler) Handle

func (h *OtelErrorHandler) Handle(err error)

Handle logs to stdout via the fallback exporter.

type StdoutExporter

type StdoutExporter struct {
	*stdoutlog.Exporter
	// contains filtered or unexported fields
}

StdoutExporter represents a custom log exporter that formats and outputs log records to stdout. It uses stdoutlog.Exporter as a base, but formats the output to make it human-readable and color-coded for different severity levels.

func NewStdoutExporter

func NewStdoutExporter(opts ...stdoutlog.Option) (*StdoutExporter, error)

NewStdoutExporter returns a new StdoutExporter instance.