Documentation ¶
Index ¶
- Constants
- func AddGID(enable bool)
- func DisableColor()
- func EnableColor()
- func EnableViperLog(enable bool)
- func FileTrace(enable bool)
- func GetLevelListString() []string
- func IsFileTrace() bool
- func IsModeColor() bool
- func IsTimeStamp() bool
- func ModeColor(enable bool)
- func SetLevel(level Level)
- func SetTracePathFilter(path string)
- func Timestamp(enable bool)
- type Entry
- func (e *Entry) Check(lvlNoErr Level) bool
- func (e *Entry) DataSet(data interface{}) *Entry
- func (e *Entry) ErrorAdd(cleanNil bool, err ...error) *Entry
- func (e *Entry) ErrorAddLib(cleanNil bool, err ...liberr.Error) *Entry
- func (e *Entry) ErrorClean() *Entry
- func (e *Entry) ErrorSet(err []error) *Entry
- func (e *Entry) FieldAdd(key string, val interface{}) *Entry
- func (e *Entry) FieldClean(keys ...string) *Entry
- func (e *Entry) FieldMerge(fields Fields) *Entry
- func (e *Entry) FieldSet(fields Fields) *Entry
- func (e *Entry) Log()
- func (e *Entry) SetGinContext(ctx *gin.Context) *Entry
- type Fields
- type FuncCustomConfig
- type FuncFormatter
- type FuncLog
- type HookFile
- type HookStandard
- type HookSyslog
- type Level
- func (l Level) Log(message string)
- func (l Level) LogData(message string, data interface{})
- func (l Level) LogError(err error) bool
- func (l Level) LogErrorCtx(levelElse Level, context string, err error) bool
- func (l Level) LogErrorCtxf(levelElse Level, contextPattern string, err error, args ...interface{}) bool
- func (l Level) LogGinErrorCtx(levelElse Level, context string, err error, c *gin.Context) bool
- func (l Level) LogGinErrorCtxf(levelElse Level, contextPattern string, err error, c *gin.Context, ...) bool
- func (l Level) Logf(format string, args ...interface{})
- func (l Level) Logrus() logrus.Level
- func (l Level) String() string
- func (l Level) Uint8() uint8
- func (l Level) WithFields(message string, fields Fields)
- type Logger
- type NetworkType
- type Options
- type OptionsFile
- type OptionsSyslog
- type StdWriter
- type SyslogFacility
- type SyslogSeverity
Constants ¶
const ( FieldTime = "time" FieldLevel = "level" FieldStack = "stack" FieldCaller = "caller" FieldFile = "file" FieldLine = "line" FieldMessage = "message" FieldError = "error" FieldData = "data" )
const ( HCLogArgs = "hclog.args" HCLogName = "hclog.name" )
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. @deprecated: create a logger and update the options like New().SetOptions...
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. @deprecated: create a logger and update the options like New().SetOptions...
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. @deprecated: create a logger and update the options like New().SetOptions...
func EnableViperLog ¶
func EnableViperLog(enable bool)
EnableViperLog enable or not the Gin Logger configuration. @deprecated: create a logger and call function SetSPF13Level like New().SetSPF13Level...
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. @deprecated: create a logger and update the options like New().SetOptions...
func GetLevelListString ¶
func GetLevelListString() []string
GetLevelListString return a list ([]string) of all string loglevel available.
func IsFileTrace ¶ added in v1.7.0
func IsFileTrace() bool
IsFileTrace will return true if trace is added or not on log message @deprecated: create a logger and get the options like New().GetOptions...
func IsModeColor ¶ added in v1.7.0
func IsModeColor() bool
IsModeColor will return true if color is configured on log message @deprecated: create a logger and get the options like New().GetOptions...
func IsTimeStamp ¶ added in v1.7.0
func IsTimeStamp() bool
IsTimeStamp will return true if timestamp is added or not on log message @deprecated: create a logger and get the options like New().GetOptions...
func ModeColor ¶ added in v1.7.0
func ModeColor(enable bool)
ModeColor will reconfigure the current logger to use or not color in messages format. This apply only for next message and only for TextFormat. @deprecated: create a logger and update the options like New().SetOptions...
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. @deprecated: create a logger and call GetLevel() like New().GetLevel...
func SetTracePathFilter ¶ added in v1.3.0
func SetTracePathFilter(path string)
SetTracePathFilter customize the filter apply to filepath on trace. @deprecated: create a logger and update the options like New().SetOptions...
Types ¶
type Entry ¶ added in v1.7.0
type Entry struct { //Time is the time of the event (can be empty time if disabled timestamp) Time time.Time `json:"time"` //Level define the level of the entry (cannot be empty or nil) Level Level `json:"level"` //Stack define the process goroutine number (can be 0 if disabled) Stack uint64 `json:"stack"` //Caller define the function caller of the entry (can be empty if trace disabled, not found or anonymous function) Caller string `json:"caller"` //File define the file function caller of the entry (can be empty if trace disabled, not found or anonymous function) File string `json:"file"` //Caller define the line in file caller of the entry (can be 0 if trace disabled, not found or anonymous function) Line uint32 `json:"line"` //Message define the main message of the entry (can be empty) Message string `json:"message"` //Error define a slice of error interface (can be nil, or a silce with one or more nil values) Error []error `json:"error"` //Data is a unknown type data to add to logger (can be nil) Data interface{} `json:"data"` //Fields are a list of custom information to add to log entry (can be nil or can overwrite Entry values) Fields Fields `json:"fields"` // contains filtered or unexported fields }
func (*Entry) ErrorAddLib ¶ added in v1.7.0
func (*Entry) ErrorClean ¶ added in v1.7.0
func (*Entry) FieldAdd ¶ added in v1.7.0
FieldAdd allow to add one couple key/val as type string/interface into the custom field of the entry.
func (*Entry) FieldClean ¶ added in v1.7.0
func (*Entry) FieldMerge ¶ added in v1.7.0
FieldMerge allow to merge a Field pointer into the custom field of the entry.
type Fields ¶ added in v1.7.0
type Fields map[string]interface{}
type FuncCustomConfig ¶ added in v1.7.0
type FuncCustomConfig func(log Logger)
type FuncFormatter ¶ added in v1.7.1
type HookFile ¶ added in v1.7.0
func NewHookFile ¶ added in v1.7.0
func NewHookFile(opt OptionsFile, format logrus.Formatter) (HookFile, error)
type HookStandard ¶ added in v1.7.0
type HookSyslog ¶ added in v1.7.0
func NewHookSyslog ¶ added in v1.7.0
func NewHookSyslog(opt OptionsSyslog, format logrus.Formatter) (HookSyslog, error)
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. @deprecated: create a logger and call GetLevel() like New().GetLevel()
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
@deprecated: create a logger and call one of this function : New().Debug, New().Info, New().Warning, New().Error, New().Fatal, New().Panic, New().LogDetails or New().Entry
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 marshaled)
@deprecated: create a logger and call one of this function : New().Debug, New().Info, New().Warning, New().Error, New().Fatal, New().Panic, New().LogDetails or New().Entry
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
@deprecated: create a logger and call one of this function : New().CheckError or New().Entry.Check
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
@deprecated: create a logger and call one of this function : New().CheckError or New().Entry.Check
func (Level) LogErrorCtxf ¶
func (l 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
@deprecated: create a logger and call one of this function : New().CheckError or New().Entry.Check
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.
@deprecated: create a logger and call one of this function : New().CheckError or New().Entry.SetGinContext.Check
func (Level) LogGinErrorCtxf ¶
func (l 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
@deprecated: create a logger and call one of this function : New().CheckError or New().Entry.SetGinContext.Check
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
@deprecated: create a logger and call one of this function : New().Debug, New().Info, New().Warning, New().Error, New().Fatal, New().Panic, New().LogDetails or New().Entry
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)
@deprecated: create a logger and call one of this function : New().Debug, New().Info, New().Warning, New().Error, New().Fatal, New().Panic, New().LogDetails or New().Entry
type Logger ¶ added in v1.7.0
type Logger interface { io.WriteCloser //SetLevel allow to change the minimal level of log message SetLevel(lvl Level) //GetLevel return the minimal level of log message GetLevel() Level //SetIOWriterLevel allow to change the minimal level of log message for io.WriterCloser interface SetIOWriterLevel(lvl Level) //GetIOWriterLevel return the minimal level of log message for io.WriterCloser interface GetIOWriterLevel() Level //SetOptions allow to set or update the options for the logger SetOptions(opt *Options) error //GetOptions return the options for the logger GetOptions() *Options //SetFields allow to set or update the default fields for all logger entry // Fields are custom information added into log message SetFields(field Fields) //GetFields return the default fields for all logger entry // Fields are custom information added into log message GetFields() Fields //Clone allow to duplicate the logger with a copy of the logger Clone() (Logger, error) //SetSPF13Level allow to plus spf13 logger (jww) to this logger SetSPF13Level(lvl Level, log *jww.Notepad) //GetStdLogger return a golang log.logger instance linked with this main logger. GetStdLogger(lvl Level, logFlags int) *log.Logger //SetStdLogger force the default golang log.logger instance linked with this main logger. SetStdLogger(lvl Level, logFlags int) //SetHashicorpHCLog force mapping default Hshicorp logger hclog to current logger SetHashicorpHCLog() //NewHashicorpHCLog return a new Hshicorp logger hclog mapped current logger NewHashicorpHCLog() hclog.Logger //Debug add an entry with DebugLevel to the logger Debug(message string, data interface{}, args ...interface{}) //Info add an entry with InfoLevel to the logger Info(message string, data interface{}, args ...interface{}) //Warning add an entry with WarnLevel to the logger Warning(message string, data interface{}, args ...interface{}) //Error add an entry with ErrorLevel level to the logger Error(message string, data interface{}, args ...interface{}) //Fatal add an entry with FatalLevel to the logger //The function will break the process (os.exit) after log entry. Fatal(message string, data interface{}, args ...interface{}) //Panic add an entry with PanicLevel level to the logger //The function will break the process (os.exit) after log entry. Panic(message string, data interface{}, args ...interface{}) //LogDetails add an entry to the logger LogDetails(lvl Level, message string, data interface{}, err []error, fields Fields, args ...interface{}) //CheckError will check if a not nil error is given and if yes, will add an entry to the logger. // Othwise if the lvlOK is given (and not NilLevel) the function will add entry and said ok CheckError(lvlKO, lvlOK Level, message string, err ...error) bool //Entry will return an entry struct to manage it (set gin context, add fields, log the entry...) Entry(lvl Level, message string, args ...interface{}) *Entry }
func GetDefault ¶ added in v1.7.0
func GetDefault() Logger
GetDefault return the default logger @deprecated: create a logger and call GetLevel() like New().GetLevel()
type NetworkType ¶ added in v1.7.0
type NetworkType uint8
const ( NetworkEmpty NetworkType = iota NetworkTCP NetworkUDP )
func MakeNetwork ¶ added in v1.7.1
func MakeNetwork(net string) NetworkType
func (NetworkType) String ¶ added in v1.7.0
func (n NetworkType) String() string
type Options ¶ added in v1.7.0
type Options struct { // DisableStandard allow disabling to write log to standard output stdout/stderr. DisableStandard bool `` /* 139-byte string literal not displayed */ // DisableStack allow to disable the goroutine id before each message. DisableStack bool `` /* 127-byte string literal not displayed */ // DisableTimestamp allow to disable the timestamp before each message. DisableTimestamp bool `` /* 143-byte string literal not displayed */ // EnableTrace allow to add the origin caller/file/line of each message. EnableTrace bool `json:"enableTrace,omitempty" yaml:"enableTrace,omitempty" toml:"enableTrace,omitempty" mapstructure:"enableTrace,omitempty"` // TraceFilter define the path to clean for trace. TraceFilter string `json:"traceFilter,omitempty" yaml:"traceFilter,omitempty" toml:"traceFilter,omitempty" mapstructure:"traceFilter,omitempty"` // DisableColor define if color could be use or not in messages format. // If the running process is not a tty, no color will be used. DisableColor bool `` /* 127-byte string literal not displayed */ // LogFile define a list of log file configuration to allow log to files. LogFile []OptionsFile `json:"logFile,omitempty" yaml:"logFile,omitempty" toml:"logFile,omitempty" mapstructure:"logFile,omitempty"` // LogSyslog define a list of syslog configuration to allow log to syslog. LogSyslog []OptionsSyslog `json:"logSyslog,omitempty" yaml:"logSyslog,omitempty" toml:"logSyslog,omitempty" mapstructure:"logSyslog,omitempty"` // contains filtered or unexported fields }
func (Options) RegisterFuncUpdateLevel ¶ added in v1.7.0
func (o Options) RegisterFuncUpdateLevel(fct FuncCustomConfig)
RegisterFuncUpdateLevel allow to register a function called when init or update level To clean function, just call RegisterFuncUpdateLevel with nil as param.
func (Options) RegisterFuncUpdateLogger ¶ added in v1.7.0
func (o Options) RegisterFuncUpdateLogger(fct FuncCustomConfig)
RegisterFuncUpdateLogger allow to register a function called when init or update of logger. To clean function, just call RegisterFuncUpdateLogger with nil as param.
type OptionsFile ¶ added in v1.7.0
type OptionsFile struct { // LogLevel define the allowed level of log for this file. LogLevel []string `json:"logLevel,omitempty" yaml:"logLevel,omitempty" toml:"logLevel,omitempty" mapstructure:"logLevel,omitempty"` // Filepath define the file path for log to file. Filepath string `json:"filepath,omitempty" yaml:"filepath,omitempty" toml:"filepath,omitempty" mapstructure:"filepath,omitempty"` // Create define if the log file must exist or can create it. Create bool `json:"create,omitempty" yaml:"create,omitempty" toml:"create,omitempty" mapstructure:"create,omitempty"` // CreatePath define if the path of the log file must exist or can try to create it. CreatePath bool `json:"createPath,omitempty" yaml:"createPath,omitempty" toml:"createPath,omitempty" mapstructure:"createPath,omitempty"` // FileMode define mode to be used for the log file if the create it. FileMode os.FileMode `json:"fileMode,omitempty" yaml:"fileMode,omitempty" toml:"fileMode,omitempty" mapstructure:"fileMode,omitempty"` // PathMode define mode to be used for the path of the log file if create it. PathMode os.FileMode `json:"pathMode,omitempty" yaml:"pathMode,omitempty" toml:"pathMode,omitempty" mapstructure:"pathMode,omitempty"` // DisableStack allow to disable the goroutine id before each message. DisableStack bool `` /* 127-byte string literal not displayed */ // DisableTimestamp allow to disable the timestamp before each message. DisableTimestamp bool `` /* 143-byte string literal not displayed */ // EnableTrace allow to add the origin caller/file/line of each message. EnableTrace bool `json:"enableTrace,omitempty" yaml:"enableTrace,omitempty" toml:"enableTrace,omitempty" mapstructure:"enableTrace,omitempty"` }
type OptionsSyslog ¶ added in v1.7.0
type OptionsSyslog struct { // LogLevel define the allowed level of log for this syslog. LogLevel []string `json:"logLevel,omitempty" yaml:"logLevel,omitempty" toml:"logLevel,omitempty" mapstructure:"logLevel,omitempty"` // Network define the network used to connect to this syslog (tcp, udp, or any other to a local connection). Network string `json:"network,omitempty" yaml:"network,omitempty" toml:"network,omitempty" mapstructure:"network,omitempty"` // Host define the remote syslog to use. // If Host and Network are empty, local syslog will be used. Host string `json:"host,omitempty" yaml:"host,omitempty" toml:"host,omitempty" mapstructure:"host,omitempty"` // Severity define the severity syslog to be used. Severity string `json:"severity,omitempty" yaml:"severity,omitempty" toml:"severity,omitempty" mapstructure:"severity,omitempty"` // Facility define the facility syslog to be used. Facility string `json:"facility,omitempty" yaml:"facility,omitempty" toml:"facility,omitempty" mapstructure:"facility,omitempty"` // Tag define the syslog tag used in linux syslog system or name of logger for windows event logger. // For window, this value must be unic for each syslog config Tag string `json:"tag,omitempty" yaml:"tag,omitempty" toml:"tag,omitempty" mapstructure:"tag,omitempty"` // DisableStack allow to disable the goroutine id before each message. DisableStack bool `` /* 127-byte string literal not displayed */ // DisableTimestamp allow to disable the timestamp before each message. DisableTimestamp bool `` /* 143-byte string literal not displayed */ // EnableTrace allow to add the origin caller/file/line of each message. EnableTrace bool `json:"enableTrace,omitempty" yaml:"enableTrace,omitempty" toml:"enableTrace,omitempty" mapstructure:"enableTrace,omitempty"` }
type SyslogFacility ¶ added in v1.7.1
type SyslogFacility uint8
const ( SyslogFacilityKern SyslogFacility = iota + 1 SyslogFacilityUser SyslogFacilityMail SyslogFacilityDaemon SyslogFacilityAuth SyslogFacilitySyslog SyslogFacilityLpr SyslogFacilityNews SyslogFacilityUucp SyslogFacilityCron SyslogFacilityAuthPriv SyslogFacilityFTP SyslogFacilityLocal0 SyslogFacilityLocal1 SyslogFacilityLocal2 SyslogFacilityLocal3 SyslogFacilityLocal4 SyslogFacilityLocal5 SyslogFacilityLocal6 SyslogFacilityLocal7 )
func MakeFacility ¶ added in v1.7.1
func MakeFacility(facility string) SyslogFacility
func (SyslogFacility) String ¶ added in v1.7.1
func (s SyslogFacility) String() string
type SyslogSeverity ¶ added in v1.7.1
type SyslogSeverity uint8
const ( SyslogSeverityEmerg SyslogSeverity = iota + 1 SyslogSeverityAlert SyslogSeverityCrit SyslogSeverityErr SyslogSeverityWarning SyslogSeverityNotice SyslogSeverityInfo SyslogSeverityDebug )
func MakeSeverity ¶ added in v1.7.1
func MakeSeverity(severity string) SyslogSeverity
func (SyslogSeverity) String ¶ added in v1.7.1
func (s SyslogSeverity) String() string