tinylog

package
v1.0.68 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tinylog provides an automated configuration of the global zerolog.Logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLevel added in v1.0.66

func SetLevel(level string) error

SetLevel sets global log level.

func SetupLogger

func SetupLogger(config ...*Config)

SetupLogger configures the global instance of zerolog.Logger.

Types

type Config

type Config struct {
	// Level is a log level to enable (default: info).
	Level string

	// TimeFormat specifies time format to use (default: "2006-01-02 15:04:05")
	TimeFormat string

	// Console is an instance of ConsoleConfig.
	Console *ConsoleConfig

	// File is an instance of FileConfig.
	File *FileConfig

	// Fields is a set of fields to include in each log line.
	Fields map[string]string
}

Config represents a configuration of the global logger.

type ConsoleConfig

type ConsoleConfig struct {
	// Disabled decides whether this output should be disabled or not (default: false).
	Disabled bool

	// Output is a writer to write logs to (default: os.Stderr).
	Output io.Writer

	// ColorsDisabled decides whether logging output should be colored or not.
	// (default: false for interactive terminals, true for others).
	ColorsDisabled bool

	// Format is a format of this output. It could be either LogText or LogJSON (default: LogText).
	Format LogFormat
}

ConsoleConfig represents a configuration for console output. This output is emitted to os.Stderr.

type FileConfig

type FileConfig struct {
	// Enabled decides whether this output should be enabled or not (default: false).
	Enabled bool

	// Location is a path to the output file (default: "log.txt").
	Location string

	// FileFlags specifies what flags to use when opening file (default: os.O_WRONLY | os.O_CREATE | os.O_APPEND).
	FileFlags int

	// FileMode specifies what mode to use when opening file (default: 0666).
	FileMode os.FileMode

	// Format is a format of this output. It could be either LogText or LogJSON (default: LogText).
	Format LogFormat
}

FileConfig represents a configuration for file output. This output is emitted to a file.

type LogFormat

type LogFormat = string

LogFormat is a logging format (text or json).

const (
	// LogText is a plaintext output.
	LogText LogFormat = "text"

	// LogJSON is a JSON-formatted output.
	LogJSON LogFormat = "json"
)

Jump to

Keyboard shortcuts

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