Documentation
¶
Overview ¶
Utility functions for logging messages and errors
Index ¶
- Constants
- Variables
- func EnableLogging(flag bool)
- func Log(messageType logType, messages ...string)
- func LogError(err error)
- func LogPlain(messageType logType, messages ...string)
- func LogReturn(messageType logType, messages ...string) string
- func Logf(messageType logType, format string, data ...interface{})
- func SetLogFile(filename string) error
- func SetLogLevel(level logType)
- func SetLogLevelByName(level string)
- func TruncateLogFileIfTooLarge(maxBytes int64) error
Constants ¶
View Source
const ( Error logType = 0 Warning logType = 1 Info logType = 2 List logType = 3 Done logType = 4 Debug logType = 5 SUCCESS int = 0 ERR_GENERIC int = 1 ERR_UNKNOWN int = 2 ERR_USAGE int = 10 ERR_INPUT int = 11 ERR_FILE_READ int = 12 ERR_CLOSABLE int = 13 ERR_CONNECTION int = 30 ERR_WRITE int = 31 ERR_PARSE int = 32 )
Variables ¶
View Source
var MapTypesToColor = map[logType]*color.Color{ Error: color.New(color.Bold, color.FgRed), Warning: color.New(color.Bold, color.FgYellow), Info: color.New(color.Bold, color.FgCyan), List: color.New(color.Bold, color.FgBlue), Done: color.New(color.Bold, color.FgGreen), Debug: color.New(color.Bold, color.FgMagenta), }
View Source
var MapTypesToPrefix = map[logType]string{ Error: MapTypesToColor[Error].Sprint("[ERR]"), Warning: MapTypesToColor[Warning].Sprint("[WRN]"), Info: MapTypesToColor[Info].Sprint("[INF]"), List: MapTypesToColor[List].Sprint("[LST]"), Done: MapTypesToColor[Done].Sprint("[DON]"), Debug: MapTypesToColor[Debug].Sprint("[DBG]"), }
Functions ¶
func EnableLogging ¶
func EnableLogging(flag bool)
EnableLogging enables or disables logging globally.
func Log ¶
func Log(messageType logType, messages ...string)
Log a timestamped message with a given logType.
func LogPlain ¶
func LogPlain(messageType logType, messages ...string)
LogPlain logs a message without a timestamp.
func Logf ¶
func Logf(messageType logType, format string, data ...interface{})
Logf functions like fmt.Printf for a given logType.
func SetLogFile ¶
SetLogFile sets the file to which logs will be written.
func SetLogLevel ¶ added in v1.2.7
func SetLogLevel(level logType)
SetLogLevel sets the current minimum log level to show
func SetLogLevelByName ¶ added in v1.2.7
func SetLogLevelByName(level string)
SetLogLevelByName sets the log level using a string (e.g., "info", "error").
func TruncateLogFileIfTooLarge ¶ added in v1.2.7
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.