logger

package
v1.10.9 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: MIT Imports: 28 Imported by: 0

README

Logger pakcage

Help manage logger. This package does not implement a logger but user logrus as logger behind. This package will simplify call of logger and allow more features like *log.Logger wrapper.

Exmaple of implement

In your file, first add the import of golib/logger :

	import liblog "github.com/nabbar/golib/logger"

Initialize the logger like this

	log := liblog.New()
	log.SetLevel(liblog.InfoLevel)

	if err := l.SetOptions(context.TODO(), &liblog.Options{
		DisableStandard:  false,
		DisableStack:     false,
		DisableTimestamp: false,
		EnableTrace:      false,
		TraceFilter:      "",
		DisableColor:     false,
		LogFile: []liblog.OptionsFile{
			{
				LogLevel: []string{
					"panic",
					"fatal",
					"error",
					"warning",
					"info",
					"debug",
				},
				Filepath:         "/path/to/my/logfile-with-trace",
				Create:           true,
				CreatePath:       true,
				FileMode:         0644,
				PathMode:         0755,
				DisableStack:     false,
				DisableTimestamp: false,
				EnableTrace:      true,
			},
		},
	}); err != nil {
		panic(err)
	}

Calling log like this :

	log.Info("Example log", nil, nil)
    
	// example with a struct name o that you want to expose in log
	// and an list of error : err1, err2 and err3
	log.LogDetails(liblog.InfoLevel, "example of detail log message with simple call", o, []error{err1, err2, err3}, nil, nil)
    

Having new log based on last logger but with some pre-defined information

    l := log.Clone(context.TODO())    
    l.SetFields(l.GetFields().Add("one-key", "one-value").Add("lib", "myLib").Add("pkg", "some-package"))
    l.Info("Example log with pre-define information", nil, nil)
    // will print line like : level=info fields.level=Info fields.time="2021-05-25T13:10:02.8033944+02:00" lib=myLib message="Example log with pre-define information" pkg=some-package stack=924 one-key=one-value
    
    // Override the field value on one log like this 
    l.LogDetails(liblog.InfoLevel, "example of detail log message with simple call", o, []error{err1, err2, err3}, liblog.NewFields().Add("lib", "another lib"), nil)
    // will print line like : level=info fields.level=Info fields.time="2021-05-25T13:10:02.8033944+02:00" lib="another lib" message="Example log with pre-define information" pkg=some-package stack=924 one-key=one-value

Implement other logger to this logger

Plug the SPF13 (Cobra / Viper) logger to this logger like this

   log.SetSPF13Level(liblog.InfoLevel, logSpf13)

Plug the Hashicorp logger hclog with the logger like this

   log.SetHashicorpHCLog()

Or get a hclog logger from the current logger like this

   hlog := log.NewHashicorpHCLog()

This call, return a go *log.Logger interface

   l := log.Clone(context.TODO())
   l.SetFields(l.GetFields().Add("one-key", "one-value").Add("lib", "myLib").Add("pkg", "some-package"))
   glog := l.GetStdLogger(liblog.ErrorLevel, log.LstdFlags|log.Lmicroseconds)

This call, will connect the default go *log.Logger

   log.SetStdLogger(liblog.ErrorLevel, log.LstdFlags|log.Lmicroseconds)

Documentation

Index

Constants

View Source
const (
	FieldTime    = "time"
	FieldLevel   = "level"
	FieldStack   = "stack"
	FieldCaller  = "caller"
	FieldFile    = "file"
	FieldLine    = "line"
	FieldMessage = "message"
	FieldError   = "error"
	FieldData    = "data"
)
View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgLogger
	ErrorValidatorError
)
View Source
const (
	HCLogArgs = "hclog.args"
	HCLogName = "hclog.name"
)
View Source
const (
	KeyCancel
)

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 NewGormLogger added in v1.8.10

func NewGormLogger(fct func() Logger, ignoreRecordNotFoundError bool, slowThreshold time.Duration) gorlog.Interface

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

func Timestamp

func Timestamp(enable bool)

Timestamp Reconfigure the current logger to add or not the timestamp before each message. @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) Check added in v1.7.0

func (e *Entry) Check(lvlNoErr Level) bool

func (*Entry) DataSet added in v1.7.0

func (e *Entry) DataSet(data interface{}) *Entry

func (*Entry) ErrorAdd added in v1.7.0

func (e *Entry) ErrorAdd(cleanNil bool, err ...error) *Entry

func (*Entry) ErrorAddLib added in v1.7.0

func (e *Entry) ErrorAddLib(cleanNil bool, err ...liberr.Error) *Entry

func (*Entry) ErrorClean added in v1.7.0

func (e *Entry) ErrorClean() *Entry

func (*Entry) ErrorSet added in v1.7.0

func (e *Entry) ErrorSet(err []error) *Entry

func (*Entry) FieldAdd added in v1.7.0

func (e *Entry) FieldAdd(key string, val interface{}) *Entry

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 (e *Entry) FieldClean(keys ...string) *Entry

func (*Entry) FieldMerge added in v1.7.0

func (e *Entry) FieldMerge(fields Fields) *Entry

FieldMerge allow to merge a Field pointer into the custom field of the entry.

func (*Entry) FieldSet added in v1.7.0

func (e *Entry) FieldSet(fields Fields) *Entry

FieldSet allow to change the custom field of the entry with the given Fields in parameter.

func (*Entry) Log added in v1.7.0

func (e *Entry) Log()

func (*Entry) SetGinContext added in v1.7.0

func (e *Entry) SetGinContext(ctx *gin.Context) *Entry

SetGinContext allow to register a gin context pointer to register the errors of the current entry intro gin Context Error Slice.

type Fields added in v1.7.0

type Fields interface {
	libctx.Config[string]
	json.Marshaler
	json.Unmarshaler

	FieldsClone(ctx context.Context) Fields
	Add(key string, val interface{}) Fields
	Logrus() logrus.Fields
	Map(fct func(key string, val interface{}) interface{}) Fields
}

func NewFields added in v1.7.0

func NewFields(ctx libctx.FuncContext) Fields

type FuncCustomConfig added in v1.7.0

type FuncCustomConfig func(log Logger)

type FuncFormatter added in v1.7.1

type FuncFormatter func() logrus.Formatter

type FuncLog added in v1.7.0

type FuncLog func() Logger

type FuncOpt added in v1.10.0

type FuncOpt func() *Options

type HookFile added in v1.7.0

type HookFile interface {
	logrus.Hook
	io.WriteCloser
	RegisterHook(log *logrus.Logger)
}

func NewHookFile added in v1.7.0

func NewHookFile(opt OptionsFile, format logrus.Formatter) (HookFile, error)

type HookStandard added in v1.7.0

type HookStandard interface {
	logrus.Hook
	io.WriteCloser
	RegisterHook(log *logrus.Logger)
}

func NewHookStandard added in v1.7.0

func NewHookStandard(opt Options, s StdWriter, lvls []logrus.Level) HookStandard

type HookSyslog added in v1.7.0

type HookSyslog interface {
	logrus.Hook
	io.WriteCloser
	RegisterHook(log *logrus.Logger)
}

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

func GetLevelString(l string) Level

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

func (l Level) Log(message string)

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

func (l Level) LogData(message string, data interface{})

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

func (l Level) LogError(err error) bool

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

func (l Level) LogErrorCtx(levelElse Level, context string, err error) bool

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

func (l Level) LogGinErrorCtx(levelElse Level, context string, err error, c *gin.Context) bool

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

func (l Level) Logf(format string, args ...interface{})

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) Logrus added in v1.7.0

func (l Level) Logrus() logrus.Level

func (Level) String

func (l Level) String() string

String Convert the current Level type to a string. E.g. PanicLevel becomes "Critical Error".

func (Level) Uint8

func (l Level) Uint8() uint8

Uint8 Convert the current Level type to a uint8 value. E.g. FatalLevel becomes 1.

func (Level) WithFields

func (l Level) WithFields(message string, fields Fields)

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

	// SetIOWriterFilter allow to filter message that contained the given pattern. If the pattern is found, the log is drop.
	SetIOWriterFilter(pattern string)

	//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

	//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

	//Access will return an entry struct to store info level access log message
	Access(remoteAddr, remoteUser string, localtime time.Time, latency time.Duration, method, request, proto string, status int, size int64) *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()

func New added in v1.7.0

func New(ctx libctx.FuncContext) Logger

New return a new logger interface pointer

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 {
	// InheritDefault define if the current options will override a default options
	InheritDefault bool `json:"inheritDefault" yaml:"inheritDefault" toml:"inheritDefault" mapstructure:"inheritDefault"`

	// 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 */

	// EnableAccessLog allow to add all message from api router for access log and error log.
	EnableAccessLog bool `` /* 139-byte string literal not displayed */

	// LogFileExtend define if the logFile given is in addition of default LogFile or a replacement.
	LogFileExtend bool `` /* 131-byte string literal not displayed */

	// LogFile define a list of log file configuration to allow log to files.
	LogFile OptionsFiles `json:"logFile,omitempty" yaml:"logFile,omitempty" toml:"logFile,omitempty" mapstructure:"logFile,omitempty"`

	// LogSyslogExtend define if the logFile given is in addition of default LogSyslog or a replacement.
	LogSyslogExtend bool `` /* 139-byte string literal not displayed */

	// LogSyslog define a list of syslog configuration to allow log to syslog.
	LogSyslog OptionsSyslogs `json:"logSyslog,omitempty" yaml:"logSyslog,omitempty" toml:"logSyslog,omitempty" mapstructure:"logSyslog,omitempty"`
	// contains filtered or unexported fields
}

func (*Options) Clone added in v1.10.0

func (o *Options) Clone() Options

func (*Options) RegisterDefaultFunc added in v1.10.0

func (o *Options) RegisterDefaultFunc(fct FuncOpt)

RegisterDefaultFunc allow to register a function called to retrieve default options for inheritDefault. If not set, the previous options will be used as default options. To clean function, just call RegisterDefaultFunc with nil as param.

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.

func (*Options) Validate added in v1.8.5

func (o *Options) Validate() liberr.Error

Validate allow checking if the options' struct is valid with the awaiting model

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"`

	// EnableAccessLog allow to add all message from api router for access log and error log.
	EnableAccessLog bool `` /* 139-byte string literal not displayed */
}

func (OptionsFile) Clone added in v1.10.0

func (o OptionsFile) Clone() OptionsFile

type OptionsFiles added in v1.10.0

type OptionsFiles []OptionsFile

func (OptionsFiles) Clone added in v1.10.0

func (o OptionsFiles) Clone() OptionsFiles

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"`

	// EnableAccessLog allow to add all message from api router for access log and error log.
	EnableAccessLog bool `` /* 139-byte string literal not displayed */
}

func (OptionsSyslog) Clone added in v1.10.0

func (o OptionsSyslog) Clone() OptionsSyslog

type OptionsSyslogs added in v1.10.0

type OptionsSyslogs []OptionsSyslog

func (OptionsSyslogs) Clone added in v1.10.0

func (o OptionsSyslogs) Clone() OptionsSyslogs

type StdWriter added in v1.7.1

type StdWriter uint8
const (
	StdOut StdWriter = iota
	StdErr
)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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