Documentation
¶
Index ¶
- Constants
- Variables
- func AddTabs(text string) (tabbedText string)
- func FormatInterfaceAsColorizedJson(data interface{}) (string, error)
- func FormatInterfaceAsJson(data interface{}) (string, error)
- func FormatMap(mapName string, field map[string]interface{}) (string, error)
- func FormatStruct(dataStructure interface{}) (string, error)
- type Level
- type MiniLogger
- func (log MiniLogger) Debug(value interface{})
- func (log MiniLogger) Debugf(format string, value ...interface{})
- func (log MiniLogger) DumpArgs()
- func (log MiniLogger) DumpSeparator(sep byte, repeat int) (string, error)
- func (log *MiniLogger) DumpStackTrace()
- func (log MiniLogger) DumpString(value string)
- func (log MiniLogger) DumpStruct(structName string, field interface{}) error
- func (log *MiniLogger) EnableIndent(enable bool)
- func (log *MiniLogger) Enter(values ...interface{})
- func (log MiniLogger) Error(value interface{})
- func (log MiniLogger) Errorf(format string, value ...interface{}) error
- func (log *MiniLogger) Exit(values ...interface{})
- func (log *MiniLogger) Flush() (err error)
- func (log *MiniLogger) FormatStruct(unformatted interface{}) string
- func (log *MiniLogger) FormatStructE(dataStructure interface{}) (string, error)
- func (log *MiniLogger) GetLevel() Level
- func (log *MiniLogger) GetLevelName() string
- func (log MiniLogger) Info(value interface{})
- func (log MiniLogger) Infof(format string, value ...interface{})
- func (log *MiniLogger) InitLogLevelAndModeFromFlags() Level
- func (log *MiniLogger) QuietModeOn() bool
- func (log *MiniLogger) SetLevel(level Level)
- func (log *MiniLogger) SetQuietMode(on bool)
- func (log MiniLogger) Trace(value interface{})
- func (log MiniLogger) Tracef(format string, value ...interface{})
- func (log MiniLogger) Warning(value interface{})
- func (log MiniLogger) Warningf(format string, value ...interface{})
Constants ¶
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
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
const (
EMPTY_STRING = "\"\""
)
Variables ¶
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
var DEFAULT_INCREMENT_RUNE = []rune("")
var DEFAULT_INDENT_RUNE = []rune("")
var DEFAULT_LEVEL = INFO
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 ¶
Note: "go-prettyjson" colorizes output for shell output
func FormatInterfaceAsJson ¶
func FormatStruct ¶
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) 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{})