logutil

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Provides an automated configuration of the global zerolog.Logger

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupLogger

func SetupLogger(c *config.Config, opts ...Opt)

SetupLogger configures the global instance of zerolog.Logger using configuration from config.Config. Configuration can be further overwritten by providing custom options as arguments. SetupLogger uses "log.*" configuration keys. Each of the available log outputs (console, file, gelf) can be configured separately by providing "log.console.*", "log.file.*" and "log.gelf.*" keys. By default, only the "console" output is enabled, and is using "text" format, console colors are enabled if the global info.Profile is set to info.ProfileDebug. Global logging level can be configured with "log.level" config key, by default it set to "info".

Types

type Config

type Config struct {
	// Console is an instance of ConsoleConfig..
	Console ConsoleConfig

	// File is an instance of FileConfig.
	File FileConfig

	// Gelf is an instance of GelfConfig.
	Gelf GelfConfig
	// contains filtered or unexported fields
}

Config represents a configuration of the global logger.

type ConsoleConfig

type ConsoleConfig struct {
	// Enabled decides whether this output should be enabled or not.
	Enabled bool

	// Colors decides whether logging output should be colored or not.
	Colors bool

	// Format is a format of this output. It could be either "text" or "json".
	Format string
}

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.
	Enabled bool

	// Location is a path to the output file.
	Location string

	// Format is a format of this output. It could be either "text" or "json".
	Format string
}

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

type GelfConfig

type GelfConfig struct {
	// Enabled decides whether this output should be enabled or not.
	Enabled bool

	// Address is an address of the UDP socket in format HOST:PORT, for example: localhost:2000.
	Address string
}

GelfConfig represents a configuration for gelf output. This output is emitted to a UDP socket.

type Opt

type Opt func(*Config)

Opt is an option to be specified to SetupLogger.

func ConsoleColors

func ConsoleColors(colors bool) Opt

ConsoleColors sets Colors parameter of the console output.

func ConsoleEnabled

func ConsoleEnabled(enabled bool) Opt

ConsoleEnabled sets Enabled parameter of the console output.

func ConsoleFormat

func ConsoleFormat(format string) Opt

ConsoleFormat sets Format parameter of the console output.

func Field

func Field(name, value string) Opt

Field adds a custom field to the logger.

func Fields

func Fields(fields map[string]string) Opt

Fields adds custom fields to the logger.

func FileEnabled

func FileEnabled(enabled bool) Opt

FileEnabled sets Enabled parameter of the file output.

func FileFormat

func FileFormat(format string) Opt

FileFormat sets Format parameter of the file output.

func FileLocation

func FileLocation(location string) Opt

FileLocation sets Location parameter of the file output.

func GelfAddress

func GelfAddress(address string) Opt

GelfAddress sets Address parameter of the gelf output.

func GelfEnabled

func GelfEnabled(enabled bool) Opt

GelfEnabled sets Enabled parameter of the gelf output.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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