logging

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package logging - Log configuration using zerolog package. Two configurations available: for dev environment(InitLogDev) and prod environment(InitLogProd)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureCallerMarshalFunc

func ConfigureCallerMarshalFunc()

ConfigureCallerMarshalFunc - truncate caller path

func InitLogDev

func InitLogDev()

InitLogDev - used for dev environment. It pretty prints log data in the console. Also, there is the option of writing the data in a file. In the log file data is written in json format. Choose file name and location

func InitLogProd

func InitLogProd()

InitLogProd - used for prod environment. It prints in the console data in json format

func InitLogTest added in v0.7.0

func InitLogTest(tst *zltest.Tester)

InitLogTest - used for testing Print in the console

Types

type Config

type Config struct {
	// Enable console logging
	ConsoleLoggingEnabled bool
	// EncodeLogsAsJson makes the log framework log JSON
	EncodeLogsAsJson bool
	// FileLoggingEnabled makes the framework log to a file
	// the fields below can be skipped if this value is false!
	FileLoggingEnabled bool
	// Directory to log to to when filelogging is enabled
	Directory string
	// Filename is the name of the logfile which will be placed inside the directory
	Filename string
	// MaxSize the max size in MB of the logfile before it's rolled
	MaxSize int
	// MaxBackups the max number of rolled files to keep
	MaxBackups int
	// MaxAge the max age in days to keep a logfile
	MaxAge int
}

Config Configuration for logging

type Logger

type Logger struct {
	*zerolog.Logger
}

func Configure

func Configure(config Config) *Logger

Configure sets up the logging framework

In production, the container logs will be collected and file logging should be disabled. However, during development it's nicer to see logs as text and optionally write to a file when debugging problems in the containerized pipeline

The output log file will be located at /var/log/service-xyz/service-xyz.log and will be rolled according to configuration set.

Jump to

Keyboard shortcuts

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