logging

package
v0.0.0-...-7c2dc49 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package logging - common package, used for logging purposes. Is a wrapper around 3-rd party logging framework.

Example (GetLogTarget)
conf := viper.New()
conf.Set("LOG_TARGET", "FILE")
conf.Set("LOG_DIR", ".")
conf.Set("LOG_FILE", "test.out")
v := getLogTarget(conf)
conf.Set("LOG_TARGET", "stdout")
v = getLogTarget(conf)
fmt.Printf("%T\n", v)
Output:

*os.File
Example (NewLogTargetFile)
conf := viper.New()
conf.Set("LOG_DIR", "")
newLogTargetFile(conf)

conf.Set("LOG_TARGET", "FILE")
conf.Set("LOG_DIR", ".")
conf.Set("LOG_FILE", "test.out")
newLogTargetFile(conf)

conf.Set("LOG_TARGET", "stdout")
newLogTargetFile(conf)
Output:

Example (SetTimeFormat_RFC)
conf := viper.New()
conf.Set("LOG_TIME_FORMAT", "RFC3339")
setTimeFormat(conf)
fmt.Println(zerolog.TimeFieldFormat)
Output:

2006-01-02T15:04:05Z07:00
Example (SetTimeFormat_Unix)
conf := viper.New()
conf.Set("LOG_TIME_FORMAT", "Unix")
setTimeFormat(conf)
fmt.Println(zerolog.TimeFieldFormat)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, args ...interface{})

Debug is wrapper over logger's debug.

func Error

func Error(msg string, args ...interface{})

Error is wrapper over logger's error.

func Fatal

func Fatal(msg string, args ...interface{})

Fatal is wrapper over logger's fatal.

func Info

func Info(msg string, args ...interface{})

Info is wrapper over logger's info.

Example
Trace("trace")
Debug("debug")
Info("info")
Warn("warn")
Error("error")
Output:

func Init

func Init(conf *viper.Viper) zerolog.Logger

Init initialises the logger with a Viper object.

Example
conf := viper.New()
l := Init(conf)
fmt.Printf("%T\n", l)
Output:

zerolog.Logger

func InitWithoutConfig

func InitWithoutConfig(logLevel string, logTarget string, logServiceName string, timeFormat string) zerolog.Logger

InitWithoutConfig initialises the logger without a Viper object.

Example
l := InitWithoutConfig("logLevel", "init1.out", "logServiceName", "timeFormat")
fmt.Printf("%T\n", l)
Output:

zerolog.Logger

func Panic

func Panic(msg string, args ...interface{})

Panic is wrapper over logger's panic.

Example
SetLogLevel("error")
defer func() {
	if err := recover(); err != nil {
		fmt.Println(err)
	}
}()
Panic("test Panic message")
Output:

test Panic message

func SetLogLevel

func SetLogLevel(logLevel string) error

SetLogLevel sets the logging level.

func Trace

func Trace(msg string, args ...interface{})

Trace is wrapper over logger's trace.

func Warn

func Warn(msg string, args ...interface{})

Warn is wrapper over logger's warn.

Types

This section is empty.

Jump to

Keyboard shortcuts

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