log

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 15 Imported by: 2 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (
	BoldBlue   = color.New(color.FgBlue, color.Bold).SprintFunc()
	BoldGreen  = color.New(color.FgGreen, color.Bold).SprintFunc()
	BoldCyan   = color.New(color.FgCyan, color.Bold).SprintFunc()
	BoldYellow = color.New(color.FgYellow, color.Bold).SprintFunc()
)

TODO enable consumer to configure colors from preset palette

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 AddTabs

func AddTabs(text string) (tabbedText string)

Often used in conjunction with formatting structures...

func FormatIndentedInterfaceAsColorizedJson added in v0.12.0

func FormatIndentedInterfaceAsColorizedJson(data interface{}, indent int, newline string) (string, error)

func FormatIndentedInterfaceAsJson added in v0.12.0

func FormatIndentedInterfaceAsJson(data interface{}, prefix string, indent string) (string, error)

func FormatInterfaceAsColorizedJson

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

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

func FormatInterfaceAsJson

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

NOTE: hardcodes indent length TODO: make configurable as a formatter field/value

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: Support Unwrap() interface (i.e., %w) on all formatted output commands; however, it is a necessity for error-type output (e.g., Errorf(), Warningf()) 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) DumpStackTrace

func (log *MiniLogger) DumpStackTrace()

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) Flush

func (log *MiniLogger) Flush() (err error)

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