gplog

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 13

Documentation

Index

Constants

View Source
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
)
View Source
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

func Colorize(c Color, text string) string

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 Custom added in v1.0.19

func Custom(customFileVerbosity int, customShellVerbosity int, s string, v ...interface{})

func Debug

func Debug(s string, v ...interface{})

func DefaultShortLogPrefixFunc added in v1.0.19

func DefaultShortLogPrefixFunc(level string) string

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 Error

func Error(s string, v ...interface{})

func Fatal

func Fatal(err error, s string, v ...interface{})

func FatalOnError

func FatalOnError(err error, output ...string)

func FatalWithoutPanic added in v1.0.2

func FatalWithoutPanic(s string, v ...interface{})

func GenerateLogFileName added in v1.0.2

func GenerateLogFileName(program, logdir string) string

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 GetHeader

func GetHeader(program string) string

func GetLogFilePath

func GetLogFilePath() string

func GetLogFileVerbosity added in v1.0.2

func GetLogFileVerbosity() int

func GetLogPrefix

func GetLogPrefix(level string) string

func GetShellLogPrefix added in v1.0.19

func GetShellLogPrefix(level string) string

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 Info

func Info(s string, v ...interface{})

func InitializeLogging

func InitializeLogging(program string, logdir string)

* 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 SetLogFileNameFunc(fileNameFunc func(string, string) string)

func SetLogFileVerbosity added in v1.0.2

func SetLogFileVerbosity(verbosity int)

func SetLogPrefixFunc

func SetLogPrefixFunc(logPrefixFunc func(string) string)

func SetLogger

func SetLogger(log *GpLogger)

func SetShellLogPrefixFunc added in v1.0.19

func SetShellLogPrefixFunc(logPrefixFunc func(string) string)

SetShellLogPrefixFunc registers a function that returns a prefix for messages that get printed to the shell console

func SetVerbosity

func SetVerbosity(verbosity int)

func Success added in v1.0.19

func Success(s string, v ...interface{})

func Verbose

func Verbose(s string, v ...interface{})

func Warn

func Warn(s string, v ...interface{})

Types

type Color added in v1.0.19

type Color int
const (
	NONE Color = iota
	RED
	GREEN
	YELLOW
)

color codes in the order of their escape character sequences

type ExitFunc added in v1.0.2

type ExitFunc func()

type GpLogger

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

func GetLogger

func GetLogger() *GpLogger

This function should only be used for testing purposes

func NewLogger

func NewLogger(stdout io.Writer, stderr io.Writer, logFile io.Writer, logFileName string, shellVerbosity int, program string, logFileVerbosity ...int) *GpLogger

stdout and stderr are passed in to this function to enable output redirection in tests.

type LogFileNameFunc added in v1.0.2

type LogFileNameFunc func(string, string) string

type LogPrefixFunc

type LogPrefixFunc func(string) string

* 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).

Jump to

Keyboard shortcuts

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