logging

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Logging

This package handles logging for Thelma.

It uses the zerolog and lumberjack libraries, and supports logging to two locations:

  • console (stderr): pretty-formatted, defaults to info level.
  • ~/.thelma/logs/thelma.log: JSON-formatted, defaults to debug level, automatically rotated

Configuration

Logging settings can be changed via Thelma configuration. Eg.

logging:
  console:
    level: debug
  file:
    level: trace

See the logConfig struct in logging.go for more configuration options.

Including Caller Information in Logs

Caller information (source file and line number) can be included in logs by setting logging.caller.enabled or THELMA_LOGGING_CALLER_ENABLED to true in config file or environment, respectively.

Usage

Clients should log messages using log.Logger:

import "github.com/rs/zerolog/log"

func doSomething() {
  	logger.Info().Str("my-useful-field", "blah").Msgf("An interesting value: %d", 123)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeLogging

func InitializeLogging(thelmaConfig config.Config) error

InitializeLogging updates the global Zerolog logger to match Thelma's configuration. It should be called once during Thelma initialization.

func NewFilteredWriter

func NewFilteredWriter(inner zerolog.LevelWriter, filterBelow zerolog.Level) zerolog.LevelWriter

Types

type FilteredWriter

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

FilteredWriter drops log messages below a specified threshold

func (*FilteredWriter) Write

func (w *FilteredWriter) Write(p []byte) (n int, err error)

func (*FilteredWriter) WriteLevel

func (w *FilteredWriter) WriteLevel(level zerolog.Level, p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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