log

package
v0.0.0-...-489b9c5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package log is a global and configurable logger pkg, based on zerolog (https://github.com/rs/zerolog)

You can congifure this logger using a toml configuration file. Here is an example configuration that has all available fields. However fields are optional. Even if you don't set some of them, logger will work well with a default value.

# A default log level for all sub modules
# must be one of this; debug/info/warn/error/fatal/panic
level = "info"

# A log output formatter
# can be chosen among this; console, console_no_color, json
formatter = "json"

# Enabling source file and line printer
caller = false

# A time stamp field format.
# e.g. in a time/format.go file
# ANSIC       = "Mon Jan _2 15:04:05 2006"
# RFC822      = "02 Jan 06 15:04 MST"
# RFC1123     = "Mon, 02 Jan 2006 15:04:05 MST"
# Kitchen     = "3:04PM"
# Stamp       = "Jan _2 15:04:05"
timefieldformat = "3:04 PM"

# If there is a sub module and it has deferent options from defaults,
# sub modules can be configed using a map struct of toml
# currently, only setting sub modules's level is allowed
[sub_module_name]
level = "error"

[can_have_multiple_module]
level = "debug"

After creating a log configuration file, you must locate that to a same directory where binary file is. Or you can register the config file path at an environment variable 'arglib_logconfig'. Because this pkg is initialized at very early stage, faster than init() func, there is no way to get an arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicInvoker

func PanicInvoker(skipTip int) string

PanicInvoker returns caller's location (file and line) that causes panic.

func SkipCaller

func SkipCaller(skip int) string

SkipCaller returns caller's location (file and line) to help debug. This passes a skip number, which is given by an arg, of callers

Types

type LazyEval

type LazyEval func() string

LazyEval can be used to evaluate an argument under a correct log level.

func DoLazyEval

func DoLazyEval(c func() string) LazyEval

DoLazyEval returns LazyEval. Unnecessary evalution can be prevented by using "%v" format string,

func (LazyEval) String

func (l LazyEval) String() string

type Logger

type Logger struct {
	*zerolog.Logger
	// contains filtered or unexported fields
}

Logger keeps configrations, and provides a funcs to print logs.

func Default

func Default() *Logger

Default returns a defulat logger. this logger does not have a module name.

func NewLogger

func NewLogger(moduleName string) *Logger

NewLogger creates and returns new logger using a current setting. To classify and debug easily, this gets moduleName and makes all co-responding sources have a same tag 'module'

func (*Logger) IsDebugEnabled

func (logger *Logger) IsDebugEnabled() bool

IsDebugEnabled is used to check whether this logger's level is debug or not. This helps to prevent heavy computation to generate debug log statements.

func (*Logger) Level

func (logger *Logger) Level() string

Level returns current logger level

Jump to

Keyboard shortcuts

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