Documentation ¶
Index ¶
- Variables
- func LoadConfig(config []byte) error
- func LoadConfigFromFile(fileName string) error
- func RegisterConfigLoaderBuilder(name string, builder ConfigLoaderBuilder)
- func RegisterFilter(name string, filter Filter)
- func RegisterFormatter(name string, formatter Formatter)
- func RegisterHandler(name string, handler Handler)
- func RegisterLogger(name string, l *Logger)
- type ConfigLoader
- type ConfigLoaderBuilder
- type DefaultFormatter
- type Filter
- type Formatter
- type GenericHandler
- type GroupFilter
- type Handler
- type Leveler
- type LogLevel
- type Logger
- func (hg *Logger) AddHandler(h Handler)
- func (hg *Logger) ClearHandlers()
- func (l *Logger) Critical(f string, v ...interface{})
- func (l *Logger) Debug(f string, v ...interface{})
- func (l *Logger) Error(f string, v ...interface{})
- func (hg *Logger) Handle(rec *Record)
- func (l *Logger) Info(f string, v ...interface{})
- func (l *Logger) LoadConfig(config map[string]interface{}) error
- func (hg *Logger) SetHandlers(handlers ...Handler)
- func (l *Logger) Warning(f string, v ...interface{})
- type Record
- type Register
- type StreamHandler
Constants ¶
This section is empty.
Variables ¶
var AutoRoot = true
AutoRoot is a switcher that controlls GetLogger result
var DefaultFormat = "[${time} ${levelname} ${sfile}:${line}] ${msg}"
DefaultFormat is default format of log message
var DefaultTimeFormat = "2006-01-02 15:04:05"
DefaultTimeFormat is default time format
var FieldHolderRegexp = regexp.MustCompile(`\$\{\w+\}`)
FieldHolderRegexp
var LevelToString = map[LogLevel]string{ DebugLevel: "DBUG", InfoLevel: "INFO", WarnLevel: "WARN", ErrorLevel: "ERRO", CriticalLevel: "CRIT", }
LevelToString is a map to translate LogLevel to a level name string
var StringToLevel = map[string]LogLevel{ "DEBUG": DebugLevel, "INFO": InfoLevel, "WARNING": WarnLevel, "ERROR": ErrorLevel, "CRITICAL": CriticalLevel, }
StringToLevel is a map to translate level name to LogLevel type
Functions ¶
func LoadConfig ¶
LoadConfig parse the json format configuration.
func LoadConfigFromFile ¶
LoadConfigFromFile read file's content and call the LoadConfig method.
func RegisterConfigLoaderBuilder ¶
func RegisterConfigLoaderBuilder(name string, builder ConfigLoaderBuilder)
RegisterConfigLoaderBuilder register the builder whith name.
func RegisterFilter ¶
RegisterFilter register a Filter with the name
func RegisterFormatter ¶
RegisterFormatter register a formatter with the name
func RegisterHandler ¶
RegisterHandler register a Handler to global manager with specific name. The Handler registered can be accessed by GetHandler method anywhere with this name.
func RegisterLogger ¶
RegisterLogger will register the logger to global manager. The logger registered can be accessed by GetLogger() method with logger's name.
Types ¶
type ConfigLoader ¶
ConfigLoader provide method to load config from bytes, string or a file.
type ConfigLoaderBuilder ¶
type ConfigLoaderBuilder func() ConfigLoader
ConfigLoaderBuilder is a function which return a ConfigLoader.
func GetConfigLoaderBuilder ¶
func GetConfigLoaderBuilder(name string) ConfigLoaderBuilder
GetConfigLoaderBuilder return a ConfigLoaderBuilder registered with this name
type DefaultFormatter ¶
DefaultFormatter struct
func NewDefaultFormatter ¶
func NewDefaultFormatter() *DefaultFormatter
NewDefaultFormatter return a new DefaultFormatter
func (*DefaultFormatter) Format ¶
func (df *DefaultFormatter) Format(rec *Record) string
Format formats a record to string
func (*DefaultFormatter) LoadConfig ¶
func (df *DefaultFormatter) LoadConfig(config map[string]interface{}) error
LoadConfig load configuration from a map
func (*DefaultFormatter) LoadConfigJSON ¶
func (df *DefaultFormatter) LoadConfigJSON(config []byte) error
LoadConfigJSON load configuration from json
type Formatter ¶
type Formatter interface { ConfigLoader Format(rec *Record) string }
Formatter interface
func GetFormatter ¶
GetFormatter return formater regeistered by the name
type GenericHandler ¶
type GenericHandler struct { GroupFilter // contains filtered or unexported fields }
GenericHandler is an abstract struct which fully implemented Handler interface expected Emit method.
func (*GenericHandler) Format ¶
func (gh *GenericHandler) Format(rec *Record) string
Format a record with formatter
func (*GenericHandler) Level ¶
func (gh *GenericHandler) Level() LogLevel
Level return log level of the handler
func (*GenericHandler) LoadConfig ¶
func (gh *GenericHandler) LoadConfig(config map[string]interface{}) error
LoadConfig load configuration from a map
func (*GenericHandler) SetFormatter ¶
func (gh *GenericHandler) SetFormatter(formatter Formatter)
SetFormatter set a new Formatter
func (*GenericHandler) SetLevel ¶
func (gh *GenericHandler) SetLevel(level LogLevel)
SetLevel set log level of handler
type GroupFilter ¶
type GroupFilter struct {
// contains filtered or unexported fields
}
GroupFilter struct
func (*GroupFilter) AddFilter ¶
func (f *GroupFilter) AddFilter(ft Filter)
AddFilter add a filter to a filter list
func (*GroupFilter) Filter ¶
func (f *GroupFilter) Filter(rec *Record) bool
Filter return true only if all the filters return true, or false if not
func (*GroupFilter) LoadConfig ¶
func (f *GroupFilter) LoadConfig(config map[string]interface{}) error
LoadConfig load configuration from a map, not implemented currenttly
type Handler ¶
Handler determines where the log message to output
func GetHandler ¶
GetHandler return the Handler registered with this name. nil will by returned if no Handler registered with this name.
type Logger ¶
type Logger struct { GroupFilter Name string Level LogLevel // contains filtered or unexported fields }
Logger is the default Logger
func Default ¶
func Default() *Logger
Default functions return a logger registered by name 'root', or a new Logger with default Handler and Formatter, and registered as 'root' automatically.
func GetLogger ¶
GetLogger return a Logger registered with the name, or the root Logger if AutoRoot is true and name is not root, or nil
func NewLogger ¶
func NewLogger() *Logger
NewLogger return a new Logger with debug level as default.
func UnregisterLogger ¶
UnregisterLogger unregister the logger from global manager, this will make the logger unreachable for others and return the logger, this's the last chance getting it. If this Logger hasn't been registered, nothing will happen and return nil
func (*Logger) AddHandler ¶
func (hg *Logger) AddHandler(h Handler)
func (*Logger) ClearHandlers ¶
func (hg *Logger) ClearHandlers()
func (*Logger) LoadConfig ¶
LoadConfig loads configuration from map.
func (*Logger) SetHandlers ¶
func (hg *Logger) SetHandlers(handlers ...Handler)
type Record ¶
type Record struct { Name string // logger name Level LogLevel // log level Time time.Time // log time LFile string // full file name SFile string // final file name Line int // line number Func string // function name Message string // log message }
Record is a struct contains all the logging information
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register is a thread-safe map
func (*Register) Register ¶
Register binds the interface and the name. If this name has been registerd, it panics.
func (*Register) Unregister ¶
Unregister unbinds the interface and the name. It returns the interface or nil
type StreamHandler ¶
type StreamHandler struct { *GenericHandler // contains filtered or unexported fields }
StreamHandler struct
func NewStreamHandler ¶
func NewStreamHandler() *StreamHandler
NewStreamHandler return a new StreamHandler
func (*StreamHandler) LoadConfig ¶
func (sh *StreamHandler) LoadConfig(config map[string]interface{}) error
LoadConfig load configuration from a map
func (*StreamHandler) SetWriter ¶
func (sh *StreamHandler) SetWriter(writer io.Writer)
SetWriter set a output writer