Documentation ¶
Index ¶
- func AddGID(enable bool)
- func DisableColor()
- func EnableColor()
- func EnableViperLog(enable bool)
- func FileTrace(enable bool)
- func GetFormatListString() []string
- func GetIOWriter(level Level, msgPrefixPattern string, msgPrefixArgs ...interface{}) io.Writer
- func GetLevelListString() []string
- func GetLogger(lvl Level, logFlags int, msgPrefixPattern string, msgPrefixArgs ...interface{}) *log.Logger
- func SetFormat(fmt Format)
- func SetLevel(level Level)
- func SetOutput(out io.WriteCloser)
- func SetStdLogger(lvl Level, logFlags int, msgPrefixPattern string, msgPrefixArgs ...interface{})
- func Timestamp(enable bool)
- type Format
- type IOWriter
- type Level
- func (level Level) Log(message string)
- func (level Level) LogData(message string, data interface{})
- func (level Level) LogError(err error) bool
- func (level Level) LogErrorCtx(levelElse Level, context string, err error) bool
- func (level Level) LogErrorCtxf(levelElse Level, contextPattern string, err error, args ...interface{}) bool
- func (level Level) LogGinErrorCtx(levelElse Level, context string, err error, c *gin.Context) bool
- func (level Level) LogGinErrorCtxf(levelElse Level, contextPattern string, err error, c *gin.Context, ...) bool
- func (level Level) Logf(format string, args ...interface{})
- func (level Level) String() string
- func (level Level) Uint8() uint8
- func (level Level) WithFields(message string, fields map[string]interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddGID ¶
func AddGID(enable bool)
AddGID Reconfigure the current logger to add or not the thread GID before each message.
func DisableColor ¶
func DisableColor()
DisableColor Reconfigure the current logger to not use color in messages format.
This apply only for next message and only for TextFormat
func EnableColor ¶
func EnableColor()
EnableColor Reconfigure the current logger to use color in messages format.
This apply only for next message and only for TextFormat
func EnableViperLog ¶
func EnableViperLog(enable bool)
EnableViperLog or not the Gin Logger configuration
func FileTrace ¶
func FileTrace(enable bool)
FileTrace Reconfigure the current logger to add or not the origin file/line of each message.
This option is apply for all message except info message
func GetFormatListString ¶
func GetFormatListString() []string
GetFormatListString return the full list (slice of string) of all available formats
func GetIOWriter ¶
GetIOWriter return a io.Writer instance to Write on logger with a specified log level
level specify the log level to use to redirect all entry to current logger msgPrefixPattern is a string pattern to prefix all entry msgPrefixArgs is a list of args to apply on the msgPrefixPattern pattern to prefix all entry
func GetLevelListString ¶
func GetLevelListString() []string
GetLevelListString return a list ([]string) of all string loglevel available
func GetLogger ¶
func GetLogger(lvl Level, logFlags int, msgPrefixPattern string, msgPrefixArgs ...interface{}) *log.Logger
GetLogger return a golang log.logger instance linked with this main logger
This function is useful to keep the format, mode, color, output... same as current config
msgPrefixPattern a pattern prefix to identify or comment all message passed throw this log.logger instance msgPrefixArgs a list of interface to apply on pattern with a fmt function
func SetFormat ¶
func SetFormat(fmt Format)
SetFormat Change the format of all log entry with the Format type given in parameter. The change is apply for next entry only
If the given Format type is not matching a correct Format type, no change will be apply.
fmt a Format type for the format to use
func SetLevel ¶
func SetLevel(level Level)
SetLevel Change the Level of all log entry with the Level type given in parameter. The change is apply for next log entry only
If the given Level type is not matching a correct Level type, no change will be apply.
level a Level type to use to specify the new level of logger message
func SetOutput ¶
func SetOutput(out io.WriteCloser)
func SetStdLogger ¶
GetLogger force the default golang log.logger instance linked with this main logger
This function is useful to keep the format, mode, color, output... same as current config
msgPrefixPattern a pattern prefix to identify or comment all message passed throw this log.logger instance msgPrefixArgs a list of interface to apply on pattern with a fmt function
Types ¶
type Format ¶
type Format uint8
Format a uint8 type customized with function to manage the result logger format
const ( // TextFormat a text format for logger entry TextFormat Format // JsonFormat a json format for logger entry JsonFormat )
func GetCurrentFormat ¶
func GetCurrentFormat() Format
GetCurrentFormat Return the current Format Type used for all log entry
func GetFormatString ¶
GetFormatString return a valid Format Type matching the given string parameter
format the string representation of a Format type
type IOWriter ¶
type IOWriter struct {
// contains filtered or unexported fields
}
IOWriter is struct redirected all entry to the current logger
type Level ¶
type Level uint8
Level a uint8 type customized with function to log message with the current log level
const ( // PanicLevel Panic level for entry log, will result on a Panic() call (trace + fatal) PanicLevel Level = iota // FatalLevel Fatal level for entry log, will result on os.Exit with error FatalLevel // ErrorLevel Error level for entry log who's meaning the caller stop his process and return to the pre caller ErrorLevel // WarnLevel Warning level for entry log who's meaning the caller don't stop his process and try to continue it WarnLevel // InfoLevel Info level for entry log who's meaning it is just an information who's have no impact on caller's process but can be useful to inform human of a state, event, success, ... InfoLevel // DebugLevel Debug level for entry log who's meaning the caller has no problem and the information is only useful to identify a potential problem who's can arrive later DebugLevel // NilLevel Nil level will never log anything and is used to completely disable current log entry. It cannot be used in the SetLogLevel function NilLevel )
func GetCurrentLevel ¶
func GetCurrentLevel() Level
GetCurrentLevel return the current loglevel setting in the logger. All log entry matching this level or below will be logged
func GetLevelString ¶
GetLevelString return a valid Level Type matching the given string parameter. If the given parameter don't represent a valid level, the InfoLevel will be return
level the string representation of a Level type
func (Level) Log ¶
Log Simple function to log directly the given message with the attached log Level
message a string message to be logged with the attached log Level
func (Level) LogData ¶
LogData Simple function to log directly the given message with given data with the attached log Level
message a string message to be logged with the attached log Level data an interface of data to be logged with the message. (In Text format, the data will be json marshalled)
func (Level) LogError ¶
LogError Simple function to log directly the given error with the attached log Level.
How iot works :
when the err is a valid error, this function will : +--- log the Error with the attached log Level +--- return true
when the err is nil, this function will : +--- return false
err an error object message to be logged with the attached log Level
func (Level) LogErrorCtx ¶
LogErrorCtx Function to test, log and inform about the given error object
How iot works :
when the err is a valid error, this function will : +--- log the Error with the attached log Level +--- return true
when the err is nil, this function will : +--- use the levelElse if valid to inform with context there is no error found +--- return false
levelElse level used if the err is nil before returning a False result context a string for the context of the current test of the error err a error object to be log with the attached log level before return true, if the err is nil, the levelElse is used to log there are no error and return false
func (Level) LogErrorCtxf ¶
func (level Level) LogErrorCtxf(levelElse Level, contextPattern string, err error, args ...interface{}) bool
LogErrorCtxf Function to test, log and inform about the given error object, but with a context based on a pattern and matching args
How iot works :
when the err is a valid error, this function will : +--- log the Error with the attached log Level +--- return true
when the err is nil, this function will : +--- use the levelElse if valid to inform with context there is no error found +--- return false
levelElse level used if the err is nil before returning a False result contextPattern a pattern string for the context of the current test of the error. This string will be used in a fmt function as pattern string err a error object to be log with the attached log level before return true, if the err is nil, the levelElse is used to log there are no error and return false args a list of interface for the context of the current test of the error. This list of interface will be used in a fmt function as the matching args for the pattern string
func (Level) LogGinErrorCtx ¶
LogGinErrorCtx Function to test, log and inform about the given error object This function will also add an Gin Tonic Error if the c parameters is a valid GinTonic Context reference.
How iot works :
- when the err is a valid error, this function will : +--- log the Error with the attached log Level +--- if the Context Gin Tonic is valid, add the Error into this context +--- return true
- when the err is nil, this function will : +--- use the levelElse if valid to inform with context there is no error found +--- return false
levelElse level used if the err is nil before returning a False result context a string for the context of the current test of the error err a error object to be log with the attached log level before return true, if the err is nil, the levelElse is used to log there are no error and return false c a valid Go GinTonic Context reference to add current error to the Gin Tonic Error Context
func (Level) LogGinErrorCtxf ¶
func (level Level) LogGinErrorCtxf(levelElse Level, contextPattern string, err error, c *gin.Context, args ...interface{}) bool
LogGinErrorCtxf Function to test, log and inform about the given error object, but with a context based on a couple of pattern and matching args. This function will also add an Gin Tonic Error if the c parameters is a valid GinTonic Context reference.
How iot works :
when the err is a valid error, this function will : +--- log the Error with the attached log Level +--- if the Context Gin Tonic is valid, add the Error into this context +--- return true
when the err is nil, this function will : +--- use the levelElse if valid to inform with context there is no error found +--- return false
levelElse level used if the err is nil before returning a False result contextPattern a pattern string for the context of the current test of the error. This string will be used in a fmt function as pattern string err a error object to be log with the attached log level before return true, if the err is nil, the levelElse is used to log there are no error and return false c a valid Go GinTonic Context reference to add current error to the Gin Tonic Error Context args a list of interface for the context of the current test of the error. This list of interface will be used in a fmt function as the matching args for the pattern string
func (Level) Logf ¶
Logf Simple function to log (to the attached log Level) with a fmt function a given pattern and arguments in parameters
format a string pattern for fmt function args a list of interface to match the references in the pattern
func (Level) String ¶
String Convert the current Level type to a string. E.g. PanicLevel becomes "Critical Error".
func (Level) Uint8 ¶
Uint8 Convert the current Level type to a uint8 value. E.g. FatalLevel becomes 1.
func (Level) WithFields ¶
WithFields Simple function to log directly the given message with given fields with the attached log Level
message a string message to be logged with the attached log Level fields a map of string key and interfaces value for a complete list of field ("field name" => value interface)