log

package
v0.0.0-...-fa8a20b Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 14 Imported by: 6

Documentation

Index

Constants

View Source
const (
	STACK_SKIP int  = 2
	MAX_INDENT uint = 8
)

Skip 2 on call stack i.e., skip public (Caller) method (e.g., "Trace()" and internal "dumpInterface()" function

View Source
const (
	DEFAULT_ENTER_TAG = "ENTER"
	DEFAULT_EXIT_TAG  = "EXIT "
)

Assure default ENTER and EXIT default tags have same fixed-length chars. for better output alignment

View Source
const (
	EMPTY_STRING = "\"\""
)

Variables

View Source
var DEFAULT_INCREMENT_RUNE = []rune("")
View Source
var DEFAULT_INDENT_RUNE = []rune("")
View Source
var DEFAULT_LEVEL = INFO
View Source
var LevelNames = map[Level]string{
	DEBUG:   color.GreenString("DEBUG"),
	TRACE:   color.CyanString("TRACE"),
	INFO:    color.WhiteString("INFO"),
	WARNING: color.HiYellowString("WARN"),
	ERROR:   color.HiRedString("ERROR"),
}

TODO: Allow colorization to be a configurable option. on (default): for human-readable targets (e.g., console); off: for (remote) logging targets (file, network) stream See colors here: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

Functions

func FormatInterfaceAsColorizedJson

func FormatInterfaceAsColorizedJson(data interface{}) (string, error)

Note: "go-prettyjson" colorizes output for shell output

func FormatInterfaceAsJson

func FormatInterfaceAsJson(data interface{}) (string, error)

func FormatMap

func FormatMap(mapName string, field map[string]interface{}) (string, error)

func FormatStruct

func FormatStruct(dataStructure interface{}) (string, error)

Types

type Level

type Level int
const (
	ERROR   Level = iota // 0 - Always output errors (stop execution)
	WARNING              // 1 - Always output warnings (continue executing)
	INFO                 // 2 - General processing information (processing milestones)
	TRACE                // 3 - In addition to INFO, output functional info. (signature, parameter)
	DEBUG                // 4 - In addition to TRACE, output internal logic and intra-functional data
)

WARNING: some functional logic may assume incremental ordering of levels

type MiniLogger

type MiniLogger struct {
	// contains filtered or unexported fields
}

TODO: allow timestamps to be turned on/off regardless of defaults TODO: allow colors to be set for each constituent part of the (TRACE) output TODO: allow multiple tags (with diff. colors) that can be enabled/disabled from the calling code

func NewDefaultLogger

func NewDefaultLogger() *MiniLogger

func NewLogger

func NewLogger(level Level) *MiniLogger

func (MiniLogger) Debug

func (log MiniLogger) Debug(value interface{})

func (MiniLogger) Debugf

func (log MiniLogger) Debugf(format string, value ...interface{})

func (MiniLogger) DumpArgs

func (log MiniLogger) DumpArgs()

func (MiniLogger) DumpSeparator

func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error)

func (MiniLogger) DumpString

func (log MiniLogger) DumpString(value string)

func (MiniLogger) DumpStruct

func (log MiniLogger) DumpStruct(structName string, field interface{}) error

func (*MiniLogger) EnableIndent

func (log *MiniLogger) EnableIndent(enable bool)

func (*MiniLogger) Enter

func (log *MiniLogger) Enter(values ...interface{})

Specialized function entry/exit trace Note: can pass in "args[]" or params as needed to have a single logging line

func (MiniLogger) Error

func (log MiniLogger) Error(value interface{})

TODO: use fmt.fError in some manner and/or os.Stderr

func (MiniLogger) Errorf

func (log MiniLogger) Errorf(format string, value ...interface{}) error

func (*MiniLogger) Exit

func (log *MiniLogger) Exit(values ...interface{})

exit and print returned values (typed) Note: can function "returns" as needed to have a single logging line

func (*MiniLogger) FormatStruct

func (log *MiniLogger) FormatStruct(unformatted interface{}) string

func (*MiniLogger) FormatStructE

func (log *MiniLogger) FormatStructE(dataStructure interface{}) (string, error)

func (*MiniLogger) GetLevel

func (log *MiniLogger) GetLevel() Level

func (*MiniLogger) GetLevelName

func (log *MiniLogger) GetLevelName() string

func (MiniLogger) Info

func (log MiniLogger) Info(value interface{})

func (MiniLogger) Infof

func (log MiniLogger) Infof(format string, value ...interface{})

func (*MiniLogger) InitLogLevelAndModeFromFlags

func (log *MiniLogger) InitLogLevelAndModeFromFlags() Level

Helper method to check for and set typical log-related flags NOTE: Assumes these do not collide with existing flags set by importing application NOTE: "go test" utilizes the Go "flags" package and allows test packages to declare additional command line arguments which can be used to set log/trace levels (e.g., `--args --trace). The values for these variables are only avail. after init() processing is completed. See: https://go.dev/doc/go1.13#testing "Testing flags are now registered in the new Init function, which is invoked by the generated main function for the test. As a result, testing flags are now only registered when running a test binary, and packages that call flag.Parse during package initialization may cause tests to fail."

func (*MiniLogger) QuietModeOn

func (log *MiniLogger) QuietModeOn() bool

func (*MiniLogger) SetLevel

func (log *MiniLogger) SetLevel(level Level)

func (*MiniLogger) SetQuietMode

func (log *MiniLogger) SetQuietMode(on bool)

func (MiniLogger) Trace

func (log MiniLogger) Trace(value interface{})

func (MiniLogger) Tracef

func (log MiniLogger) Tracef(format string, value ...interface{})

func (MiniLogger) Warning

func (log MiniLogger) Warning(value interface{})

func (MiniLogger) Warningf

func (log MiniLogger) Warningf(format string, value ...interface{})

Jump to

Keyboard shortcuts

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