logging

package
v0.0.0-...-7726842 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 8 Imported by: 11

Documentation

Overview

Package logging holds the code to have a uniform logging style for all output.

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 (SetLogLevel)
conf := viper.New()
conf.Set("LOG_LEVEL", "AA")
setLogLevel(conf)
conf.Set("LOG_LEVEL", "debug")
setLogLevel(conf)
fmt.Printf("%v\n", zerolog.GlobalLevel())
Output:

debug
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{})

func Error

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

func Error1

func Error1(err error)

Error1 prints an Error level log for an error

func ErrorAndPanic

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

ErrorAndPanic is now deprecated. It is equivalent to Panic.

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

test ErrorAndPanic message

func Fatal

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

func Info

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

func InfoEnabled

func InfoEnabled() bool

InfoEnabled returns true if Info log level is enabled.

func Init

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

zerolog.Logger

func Init1

func Init1(logLevel string, logTarget string, logServiceName string) zerolog.Logger

Init1 initialises the logger without a Viper object

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

zerolog.Logger

func Panic

func Panic(msg string, args ...interface{})
Example
defer func() {
	if err := recover(); err != nil {
		fmt.Println(err)
	}
}()
Panic("test Panic message")
Output:

test Panic message

func SetLogLevel

func SetLogLevel(logLevel string)
Example
SetLogLevel("AA")
SetLogLevel("debug")
fmt.Printf("%v\n", zerolog.GlobalLevel())
Output:

debug

func Trace

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

func Warn

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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