echo

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 6 Imported by: 0

README

echo

A temporary echo proxy to log/slog. Only used for the transition period until our projects are fully migrated. Please keep in mind this is an incomplete implementation, only functions used in osbuild project are present.

How to use

package main

import (
	"github.com/labstack/echo/v4"

	echoproxy "github.com/osbuild/logging/pkg/echo"
)

func main() {
	e := echo.New()
	e.Logger = echoproxy.NewProxy()

	// ...
}

Per-request logger

It is possible to set individual echo proxy for each request which performs context passing into every single logging record automatically. Just make sure to put middleware that sets context fields before echo proxy middleware:

s1 := echo.New()
s1.Logger = echoproxy.NewProxyFor(slog.Default())
// strc middleware sets "trace_id" and "request_id"
s1.Use(echo.WrapMiddleware(strc.NewMiddleware(slog.Default())))
// pass the context with the fields into echo stack
s1.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
	return func(c echo.Context) error {
		c.SetLogger(echoproxy.NewProxyContextFor(slog.Default(), c.Request().Context()))
		return next(c)
	}
})

By default, only trace_id and build_id are logged by the multi handler, this can be customized by providing a callback function via NewMultiHandlerCustom.

Full example

For a full web example run:

go run github.com/osbuild/logging/internal/example_web/

Documentation

Overview

Implements the echo Logger proxy to log/slog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefault

func SetDefault(p *Proxy)

Types

type Logger

type Logger interface {
	Output() io.Writer
	SetOutput(w io.Writer)
	Prefix() string
	SetPrefix(p string)
	Level() log.Lvl
	SetLevel(v log.Lvl)
	SetHeader(h string)
	Print(i ...interface{})
	Printf(format string, args ...interface{})
	Printj(j log.JSON)
	Debug(i ...interface{})
	Debugf(format string, args ...interface{})
	Debugj(j log.JSON)
	Info(i ...interface{})
	Infof(format string, args ...interface{})
	Infoj(j log.JSON)
	Warn(i ...interface{})
	Warnf(format string, args ...interface{})
	Warnj(j log.JSON)
	Error(i ...interface{})
	Errorf(format string, args ...interface{})
	Errorj(j log.JSON)
	Fatal(i ...interface{})
	Fatalj(j log.JSON)
	Fatalf(format string, args ...interface{})
	Panic(i ...interface{})
	Panicj(j log.JSON)
	Panicf(format string, args ...interface{})
}

Logger defines the logging interface.

type Proxy

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

Proxy is a proxy type for logrus.Logger

func Default

func Default() *Proxy

func NewProxy

func NewProxy() *Proxy

NewProxy creates a new Proxy for the standard logger

func NewProxyFor

func NewProxyFor(logger *slog.Logger) *Proxy

NewProxyFor creates a new Proxy for a particular logger

func NewProxyWithContextFor added in v0.0.5

func NewProxyWithContextFor(logger *slog.Logger, ctx context.Context) *Proxy

NewProxyWithContextFor creates a new Proxy for a particular logger with a particular context.

func (*Proxy) Debug

func (p *Proxy) Debug(args ...interface{})

func (*Proxy) Debugf

func (p *Proxy) Debugf(format string, args ...interface{})

func (*Proxy) Debugj

func (p *Proxy) Debugj(j log.JSON)

func (*Proxy) Error

func (p *Proxy) Error(args ...interface{})

func (*Proxy) Errorf

func (p *Proxy) Errorf(format string, args ...interface{})

func (*Proxy) Errorj

func (p *Proxy) Errorj(j log.JSON)

func (*Proxy) Fatal

func (p *Proxy) Fatal(args ...interface{})

func (*Proxy) Fatalf

func (p *Proxy) Fatalf(format string, args ...interface{})

func (*Proxy) Fatalj

func (p *Proxy) Fatalj(j log.JSON)

func (*Proxy) Info

func (p *Proxy) Info(args ...interface{})

func (*Proxy) Infof

func (p *Proxy) Infof(format string, args ...interface{})

func (*Proxy) Infoj

func (p *Proxy) Infoj(j log.JSON)

func (*Proxy) Level

func (p *Proxy) Level() log.Lvl

func (*Proxy) Output

func (p *Proxy) Output() io.Writer

func (*Proxy) Panic

func (p *Proxy) Panic(args ...interface{})

func (*Proxy) Panicf

func (p *Proxy) Panicf(format string, args ...interface{})

func (*Proxy) Panicj

func (p *Proxy) Panicj(j log.JSON)

func (*Proxy) Prefix

func (p *Proxy) Prefix() string

func (*Proxy) Print

func (p *Proxy) Print(args ...interface{})

func (*Proxy) Printf

func (p *Proxy) Printf(format string, args ...interface{})

func (*Proxy) Printj

func (p *Proxy) Printj(j log.JSON)

func (*Proxy) SetHeader

func (p *Proxy) SetHeader(h string)

func (*Proxy) SetLevel

func (p *Proxy) SetLevel(l log.Lvl)

func (*Proxy) SetOutput

func (p *Proxy) SetOutput(w io.Writer)

func (*Proxy) SetPrefix

func (p *Proxy) SetPrefix(prefix string)

func (*Proxy) Warn

func (p *Proxy) Warn(args ...interface{})

func (*Proxy) Warnf

func (p *Proxy) Warnf(format string, args ...interface{})

func (*Proxy) Warnj

func (p *Proxy) Warnj(j log.JSON)

func (*Proxy) Write

func (p *Proxy) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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