logger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogLevel

func LogLevel(from VarFrom) (level zapcore.Level, err error)

LogLevel returns zapcore.Level received from the given VarFrom.

func NewDevelopmentLogger

func NewDevelopmentLogger(opts ...Options) (*zap.Logger, error)

NewDevelopmentLogger creates a new zap.Logger for logging development and deployment tools with optional Options.

func NewProductionLogger

func NewProductionLogger(opts ...Options) (*zap.Logger, error)

NewProductionLogger creates a new zap.Logger for logging production with optional Options.

Types

type Options

type Options struct {
	// These Extra options will be passed into [zap.Config.Build] when a logger
	// creation function is called right before the new [zap.Logger] is returned.
	Extra []zap.Option

	// Enable verbose output. [Options.Level] will be ignored and logging level
	// will be set to [zap.DebugLevel].
	EnableVerbose bool

	// Enable colorful output.
	EnableColor bool

	Level zapcore.Level
}

Options is options to create a new zap.Logger.

func NewOptions

func NewOptions(level zapcore.Level, opts ...zap.Option) *Options

NewOptions creates a new Options with the given logging level and optional zap.Option's.

func (*Options) ColorFlag

func (opts *Options) ColorFlag(set *flag.FlagSet)

ColorFlag defines a new "color" flag for the given flag.FlagSet. The flag will set the [Options.EnableColor] field.

func (*Options) LogLevelFlag

func (opts *Options) LogLevelFlag(set *flag.FlagSet)

LogLevelFlag defines a new "loglevel" flag for the given flag.FlagSet. The flag will set the [Options.Level] field.

func (*Options) SetLogLevel

func (opts *Options) SetLogLevel(from VarFrom) (err error)

SetLogLevel sets [Options.Level] to the value received from the given VarFrom.

func (*Options) VerboseFlag

func (opts *Options) VerboseFlag(set *flag.FlagSet)

VerboseFlag defines a new "verbose" flag for the given flag.FlagSet. The flag will set the [Options.EnableVerbose] field.

type VarFrom

type VarFrom func() (value string, err error)

VarFrom reads the value from a source.

func FromDotEnvFiles

func FromDotEnvFiles(name string, filenames ...string) VarFrom

FromDotEnvFiles returns VarFrom that reads the variable with the given name from the optional file(s) with the given filename(s) (default: .env).

func FromEnv

func FromEnv(name string) VarFrom

FromEnv returns VarFrom that reads the environment variable with the given name.

Jump to

Keyboard shortcuts

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