log

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 7 Imported by: 5

README

Common Go logging code shared between my projects

GoDoc Build Coverage Go Report Card

License

This project is subject to the the MIT License. See LICENSE information for details.

Documentation

Overview

Package log provides functionality for easy usage of the github.com/rs/zerolog logging framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(w io.Writer, timestamp bool) *zerolog.Logger

NewLogger creates a new github.com/rs/zerolog.Logger for the given options.

func ResetRootLogger

func ResetRootLogger() *zerolog.Logger

ResetRootLogger resets the root logger to it's default.

func RootLogger

func RootLogger() *zerolog.Logger

RootLogger gets the current root logger.

func SetLevel

func SetLevel(level zerolog.Level)

SetLevel sets the log level.

func SetRootLogger

func SetRootLogger(logger *zerolog.Logger, level zerolog.Level, timeFieldFormat string) *zerolog.Logger

SetRootLogger sets a new root logger as well as log level and time field format.

func SetRootLoggerFromConfig

func SetRootLoggerFromConfig(config Config) *zerolog.Logger

SetRootLoggerFromConfig sets a new root logger as well as log level and time field format using a github.com/hdecarne-github/go-log/Config interface.

func SetTimeFieldFormat

func SetTimeFieldFormat(timeFieldFormat string)

SetTimeFieldFormat sets the time field format.

Types

type Config

type Config interface {
	// Logger creates the [github.com/rs/zerolog.Logger]
	Logger() *zerolog.Logger
	// Level gets the global log level to use.
	Level() zerolog.Level
	// TimeFieldFormat gets the time field format to use.
	TimeFieldFormat() string
}

Config provides a plugable interface for runtime logging configuration.

type YAMLConfig

type YAMLConfig struct {
	LevelOption           string                    `yaml:"level"`
	TimestampOption       bool                      `yaml:"timestamp"`
	TimeFieldFormatOption string                    `yaml:"timeFieldFormat"`
	Console               console.YAMLConsoleConfig `yaml:"console"`
	File                  file.YAMLFileConfig       `yaml:"file"`
	Syslog                syslog.YAMLSyslogConfig   `yaml:"syslog"`
}

YAMLConfig supports a YAML file based logging configuration.

func (*YAMLConfig) Level

func (config *YAMLConfig) Level() zerolog.Level

func (*YAMLConfig) Logger

func (config *YAMLConfig) Logger() *zerolog.Logger

func (*YAMLConfig) TimeFieldFormat

func (config *YAMLConfig) TimeFieldFormat() string

Directories

Path Synopsis
Package console provides console logging related functionality.
Package console provides console logging related functionality.
Package file provides file logging related functionality.
Package file provides file logging related functionality.
Package syslog provides syslog logging related functionality.
Package syslog provides syslog logging related functionality.

Jump to

Keyboard shortcuts

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