fxeventzerolog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: MIT Imports: 3 Imported by: 0

README

fxevent-zerolog

A structured logger for Uber's Fx that leverages the performance and flexibility of zerolog. This package implements the fxevent.Logger interface, enabling seamless integration of zerolog into your Fx applications.

Motivation

While Fx provides a powerful dependency injection framework, its default logging is not always ideal for high-performance or structured logging needs. This package bridges that gap, allowing you to use zerolog as the event logger for Fx, with full support for log levels, structured fields, and custom configuration.

Features

  • Implements fxevent.Logger for drop-in Fx compatibility
  • Full support for zerolog's structured logging and log levels
  • Customizable log and error levels
  • Safe defaults (no panics on nil logger)
  • Comprehensive test coverage

Installation

go get github.com/amari/fxevent-zerolog

Usage

import (
	"github.com/rs/zerolog"
	"go.uber.org/fx"
	"github.com/amari/fxevent-zerolog"
)

func main() {
	logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
	app := fx.New(
        fx.Supply(&logger),
		fx.WithLogger(fxeventzerolog.New),
	)
	app.Run()
}

API

See zerolog.go for full documentation and implementation details.

Testing

This project includes comprehensive unit tests covering all major event types and behaviors. Run tests with:

go test -v

License

This project is MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(logger *zerolog.Logger) fxevent.Logger

New creates a new Logger that writes to the provided zerolog.Logger.

Types

type Logger

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

Logger implements the fxevent.Logger interface using zerolog for structured logging. It allows configuring log levels for error and non-error events.

func (*Logger) LogEvent

func (l *Logger) LogEvent(event fxevent.Event)

LogEvent logs the given Fx event to the underlying zerolog logger. It handles all standard fxevent.Event types and logs relevant fields for each.

Jump to

Keyboard shortcuts

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