Documentation ¶
Index ¶
- Constants
- func Colorize(c Color, text string) string
- func Custom(customFileVerbosity int, customShellVerbosity int, s string, v ...interface{})
- func Debug(s string, v ...interface{})
- func DefaultShortLogPrefixFunc(level string) string
- func Error(s string, v ...interface{})
- func Fatal(err error, s string, v ...interface{})
- func FatalOnError(err error, output ...string)
- func FatalWithoutPanic(s string, v ...interface{})
- func GenerateLogFileName(program, logdir string) string
- func GetColorize() bool
- func GetErrorCode() int
- func GetHeader(program string) string
- func GetLogFilePath() string
- func GetLogFileVerbosity() int
- func GetLogPrefix(level string) string
- func GetShellLogPrefix(level string) string
- func GetVerbosity() int
- func Info(s string, v ...interface{})
- func InitializeLogging(program string, logdir string)
- func SetColorize(shouldColorize bool)
- func SetErrorCode(code int)
- func SetExitFunc(pExitFunc func())
- func SetLogFileNameFunc(fileNameFunc func(string, string) string)
- func SetLogFileVerbosity(verbosity int)
- func SetLogPrefixFunc(logPrefixFunc func(string) string)
- func SetLogger(log *GpLogger)
- func SetShellLogPrefixFunc(logPrefixFunc func(string) string)
- func SetVerbosity(verbosity int)
- func Success(s string, v ...interface{})
- func Verbose(s string, v ...interface{})
- func Warn(s string, v ...interface{})
- type Color
- type ExitFunc
- type GpLogger
- type LogFileNameFunc
- type LogPrefixFunc
Constants ¶
const ( /* * The following constants representing the current logging level, and are * cumulative (that is, setting the log level to Debug will print all Error-, * Info-, and Verbose-level messages in addition to Debug-level messages). * * Log levels for terminal output and logfile output are separate, and can be * set independently. By default, a new logger will have a verbosity of INFO * for terminal output and DEBUG for logfile output. */ LOGERROR = iota LOGINFO LOGVERBOSE LOGDEBUG )
const ESCAPE = "\x1b"
ESCAPE - ASCII escape character to start color character sequences
Variables ¶
This section is empty.
Functions ¶
func Colorize ¶ added in v1.0.19
Colorize wraps a string with special characters so that the string has a provided color when output to the console colorization happens only if the logger flag `colorize` is set to true. The function is exported to allow colorization outside the logging methods, such as when recovering from a `panic` when Fatal messages are logged.
func DefaultShortLogPrefixFunc ¶ added in v1.0.19
DefaultShortLogPrefixFunc returns a short prefix for messages typically sent to the shell console It does not include the timestamp and other system information that would be found in a log file and only displays the message logging level for WARNING, ERROR, and CRITICAL levels. This function must be explicitly set by the users of the logger by calling SetShellLogPrefixFunc(gplog.DefaultShortLogPrefixFunc)
func FatalOnError ¶
func FatalWithoutPanic ¶ added in v1.0.2
func FatalWithoutPanic(s string, v ...interface{})
func GenerateLogFileName ¶ added in v1.0.2
func GetColorize ¶ added in v1.0.19
func GetColorize() bool
GetColorize returns whether the colorization of shell console output has been enabled
func GetErrorCode ¶
func GetErrorCode() int
func GetLogFilePath ¶
func GetLogFilePath() string
func GetLogFileVerbosity ¶ added in v1.0.2
func GetLogFileVerbosity() int
func GetLogPrefix ¶
func GetShellLogPrefix ¶ added in v1.0.19
GetShellLogPrefix returns a prefix to prepend to the message before sending it to the shell console Use this mechanism if it is desired to have different prefixes for messages sent to the console and to the log file. A caller must first set a custom function that will provide a custom prefix by calling SetShellLogPrefixFunc. If the custom function has not been provided, this function returns a prefix produced by the GetLogPrefix function, so that the prefixes for the shell console and the log file will be the same.
func GetVerbosity ¶
func GetVerbosity() int
func InitializeLogging ¶
* Multiple calls to InitializeLogging can be made if desired; the first call * will initialize the logger as a singleton and subsequent calls will return * the same Logger instance.
func SetColorize ¶ added in v1.0.19
func SetColorize(shouldColorize bool)
SetColorize sets the flag defining whether to colorize the output to the shell console. The output to log files is never colorized, even if the flag is set to true. Shell console output colorization depends on the message levels: red - for CRITICAL (non-panic) and ERROR levels yellow - for WARNING levels green - for INFO levels produced via Success function call only no color - for all other levels
func SetErrorCode ¶
func SetErrorCode(code int)
func SetExitFunc ¶ added in v1.0.2
func SetExitFunc(pExitFunc func())
func SetLogFileNameFunc ¶ added in v1.0.2
func SetLogFileVerbosity ¶ added in v1.0.2
func SetLogFileVerbosity(verbosity int)
func SetLogPrefixFunc ¶
func SetShellLogPrefixFunc ¶ added in v1.0.19
SetShellLogPrefixFunc registers a function that returns a prefix for messages that get printed to the shell console
func SetVerbosity ¶
func SetVerbosity(verbosity int)
Types ¶
type LogFileNameFunc ¶ added in v1.0.2
type LogPrefixFunc ¶
* Leveled logging output functions using the above log levels are implemented * below. Info(), Verbose(), and Debug() print messages when the log level is * set at or above the log level matching their names. Warn(), Error(), and * Fatal() always print their messages regardless of the current log level. * * The intended usage of these functions is as follows: * - Info: Messages that should always be written unless the user explicitly * suppresses output, e.g. notifying the user that a step has completed. * - Verbose: More detailed messages that are mostly useful to the user, e.g. * printing information about a function's substeps for progress tracking. * - Debug: More detailed messages that are mostly useful to developers, e.g. * noting that a function has been called with certain arguments. * - Warn: Messages indicating unusual but not incorrect behavior that a user * may want to know, e.g. that certain steps are skipped when using * certain flags. These messages are shown even if output is suppressed. * - Error: Messages indicating that an error has occurred, but that the program * can continue, e.g. one function call in a group failed but others succeeded. * - Fatal: Messages indicating that the program cannot proceed, e.g. the database * cannot be reached. This function will exit the program after printing * the error message. * - FatalWithoutPanic: Same as Fatal, but will not trigger panic. Just exit(1).