logger

package
v0.0.0-...-5e472c2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 5 Imported by: 0

README

logger

Package logger offers an fx module that utilizes slog for logging.

Provides:

  • Logger (type: *slog.Logger, name: "logger")

Depends on:

  • Output, optional (type: io.Writer, name: "logger_output", default: os.Stdout)

You can configure it using these environment variables:

  • LOG_LEVEL
  • LOG_FORMAT

The valid log levels:

  • debug
  • info (default)
  • warn
  • error

The valid log formats:

  • text (default)
  • json

Documentation

Overview

Package logger offers an fx module that utilizes slog for logging.

Provides:

  • Logger (type: *slog.Logger, name: "logger")

Depends on:

  • Output, optional (type: io.Writer, name: "logger_output", default: os.Stdout)

You can configure it using these environment variables:

  • LOG_LEVEL
  • LOG_FORMAT

The valid log levels:

  • debug
  • info (default)
  • warn
  • error

The valid log formats:

  • text (default)
  • json

Index

Constants

View Source
const (
	FormatText = "text"
	FormatJSON = "json"
)

Log formats.

View Source
const (
	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
)

Log levels.

Variables

View Source
var (
	ErrInvalidFormat = errors.New("invalid format")
	ErrInvalidLevel  = errors.New("invalid level")
)

Errors.

View Source
var Module = fx.Module(
	"logger",
	fx.Provide(
		New,
	),
	fx.Provide(
		fx.Private,

		parseConfig,
	),
)

Module is the logger module.

Functions

This section is empty.

Types

type Config

type Config struct {
	Format string
	Level  string
}

Config is the logger config.

type Parameter

type Parameter struct {
	fx.In

	Output io.Writer `name:"logger_output" optional:"true"`
	Config Config
}

Parameter is the input parameter of the New function.

type Result

type Result struct {
	fx.Out

	Logger *slog.Logger
}

Result is the output result of the New function.

func New

func New(parameter Parameter) (Result, error)

New creates a new logger.

Jump to

Keyboard shortcuts

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