logger

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

func Ctx(ctx context.Context) *zerolog.Logger

Ctx retrieves the zerolog.Logger from the provided context.

This function extracts the zerolog.Logger instance associated with the given context. It is useful for logging within the context of a request or operation.

Parameters: - ctx context.Context: The context from which to retrieve the logger.

Returns: - *zerolog.Logger: The logger associated with the context.

func Debug

func Debug() *zerolog.Event

Debug logs a debug level message using the zerolog.Logger from the provided context.

func Error

func Error() *zerolog.Event

Error logs an error level message using the zerolog.Logger from the provided context.

func Fatal

func Fatal() *zerolog.Event

Fatal logs a fatal level message using the zerolog.Logger from the provided context.

func Info

func Info() *zerolog.Event

Info logs an info level message using the zerolog.Logger from the provided context.

func Log

func Log() *zerolog.Event

Log logs a no-level message using the zerolog.Logger from the provided context.

func Panic

func Panic() *zerolog.Event

Panic logs a panic level message using the zerolog.Logger from the provided context.

func Register

func Register(ctx context.Context, opts *Options) error

func Shutdown

func Shutdown(ctx context.Context) error

func Trace

func Trace() *zerolog.Event

Trace logs a trace level message using the zerolog.Logger from the provided context.

func Warn

func Warn() *zerolog.Event

Warn logs a warn level message using the zerolog.Logger from the provided context.

func WithFields added in v0.2.0

func WithFields(ctx context.Context, fields map[string]interface{}) *zerolog.Logger

WithFields adds fields to the zerolog.Logger in the provided context.

This function retrieves the zerolog.Logger from the context, adds the specified fields to the logger's context, and returns the updated logger. It is useful for adding contextual information to logs.

Parameters: - ctx context.Context: The context from which to retrieve the logger. - fields map[string]any: The fields to add to the logger's context.

Returns: - *zerolog.Logger: The updated logger with the added fields.

Types

type Logger

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

func NewLogger

func NewLogger(ctx context.Context, config *Options) (*Logger, error)

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Provider

func (l *Logger) Provider() *log.LoggerProvider

func (*Logger) Shutdown

func (l *Logger) Shutdown(ctx context.Context) error

type Option

type Option interface {
	ApplyLoggerOption(*Options)
}

Option defines an interface for applying meter options.

func WithCommonOptions

func WithCommonOptions(opts ...Option) Option

func WithEnabled

func WithEnabled(enabled bool) Option

WithEnabled returns an Option that sets the enabled state of the meter. This function is a convenient way to enable or disable the meter functionality.

func WithExportInterval

func WithExportInterval(interval time.Duration) Option

WithExportInterval returns an Option that sets the read interval of the meter. This function is a convenient way to specify how often the meter reads data.

func WithLevel

func WithLevel(l level.Level) Option

WithLevel returns an Option that sets the log level of the meter. This function is a convenient way to specify the log level for the meter.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter returns an Option that sets the writer for the meter. This function is a convenient way to specify the writer to which logs are written.

type Options

type Options struct {
	Enabled bool // Enabled specifies whether the meter is enabled.

	ExportInterval time.Duration // ExportInterval specifies the interval at which the meter exports data.
	Level          level.Level   // Level specifies the log level of the meter.

	Writer io.Writer // Writer specifies the writer to write logs to.
}

Options holds configuration options for a meter.

func NewConfig

func NewConfig(opts ...Option) Options

func (*Options) IsEnabled

func (c *Options) IsEnabled() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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