logutil

package
v1.1.64 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package logutil 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(opts ...Opt)

SetupLogger configures the global instance of zerolog.Logger. Default configuration can be overwritten by providing custom options as arguments.

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

	// 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 (default: true).
	Enabled bool

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

	// Colors decides whether logging output should be colored or not (default: true for interactive terminals).
	Colors 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 GelfConfig

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

	// Address is an address of the UDP socket in format HOST:PORT.
	Address string
}

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

type LogFormat added in v1.1.51

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"
)

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 LogFormat) Opt

ConsoleFormat sets Format parameter of the console output.

func ConsoleOutput added in v1.1.57

func ConsoleOutput(output io.Writer) Opt

ConsoleOutput sets the writer to write logs to.

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 FileFlags added in v1.1.51

func FileFlags(flags int) Opt

FileFlags specifies what flags to use when opening file.

func FileFormat

func FileFormat(format LogFormat) 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 FileMode added in v1.1.51

func FileMode(mode os.FileMode) Opt

FileMode specifies what mode to use when opening file.

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.

func Level added in v1.1.47

func Level(level string) Opt

Level sets logging level to enable.

func TimeFormat added in v1.1.51

func TimeFormat(format string) Opt

TimeFormat specifies time format to use

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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