logmod

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

logmod

Using logmod takes care of exporting logs to otel endpoint and flushing log buffers before the application exits.

package main

import (
	"log/slog"
	"time"

	"github.com/go-srvc/mods/logmod"
	"github.com/go-srvc/mods/tickermod"
	"github.com/go-srvc/srvc"
)

func main() {
	srvc.RunAndExit(
		logmod.New(),
		tickermod.New(
			tickermod.WithInterval(5*time.Second),
			tickermod.WithFunc(func() {
				// Slog uses now otelslog bridge configured by logmod.
				slog.Info("Hello, World!")
			}),
		),
	)
}

Documentation

Overview

Package logmod provides OpenTelemetry trace provider as a module.

Index

Examples

Constants

View Source
const ErrMissingProvider = errStr("log provider not set")
View Source
const ID = "logmod"

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*Provider) error

func WithEnv added in v0.1.5

func WithEnv() Opt

WithEnv uses OTEL_EXPORTER_OTLP_TRACES_PROTO and OTEL_EXPORTER_OTLP_PROTO environment variable to set exporter. Accepted values are:

  • http
  • grpc
  • stdout

If no value is provided, stdout is used.

func WithGRPC

func WithGRPC() Opt

WithGRPC creates log provider with batch processor using grpc exporter from OTEL_* env configs. Env variables: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc

func WithHTTP

func WithHTTP() Opt

WithHTTP creates log provider with batch processor using http exporter from OTEL_* env configs. Env variables: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp

func WithProvider

func WithProvider(exp *log.LoggerProvider) Opt

WithProvider sets the underlying trace provider for module.

func WithProviderFn

func WithProviderFn(fn func() (*log.LoggerProvider, error)) Opt

WithProviderFn sets the underlying trace provider for module using given function.

func WithStdout added in v0.1.5

func WithStdout(opt ...stdoutlog.Option) Opt

WithStdout creates log provider with stdout exporter.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Opt) *Provider

New creates log provider module with sane defaults if no options are provided. Default options are: WithEnv. For instructions on how to integrate log provider with logger of your choice, see the list of ready made bridge libraries: https://opentelemetry.io/ecosystem/registry/?language=go&component=log-bridge

Example
package main

import (
	"github.com/go-srvc/mods/logmod"
	"github.com/go-srvc/srvc"
)

func main() {
	srvc.RunAndExit(
		logmod.New(),
	)
}
Output:

func (*Provider) ID

func (p *Provider) ID() string

func (*Provider) Init

func (p *Provider) Init() error

func (*Provider) Run

func (p *Provider) Run() error

func (*Provider) Stop

func (p *Provider) Stop() error

Jump to

Keyboard shortcuts

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