Documentation ¶
Index ¶
- Constants
- Variables
- func Alert(fmt string, args ...interface{})
- func Close()
- func Critical(fmt string, args ...interface{})
- func Debug(fmt string, args ...interface{})
- func Emergency(fmt string, args ...interface{})
- func Error(fmt string, args ...interface{})
- func Info(fmt string, args ...interface{})
- func Notice(fmt string, args ...interface{})
- func Register(w Writer)
- func SetLayout(layout string)
- func SetLevel(lvl int)
- func SetLog(config []byte) (err error)
- func SetLogWithConf(file string) (err error)
- func SetupLog(lc LogConfig) (err error)
- func Warn(fmt string, args ...interface{})
- func WithFullPath(show bool)
- func WithFuncName(show bool)
- type ConsoleWriter
- type ConsoleWriterOptions
- type FileWriter
- type FileWriterOptions
- type Flusher
- type KafKaMSGFields
- type KafKaWriter
- type KafKaWriterOptions
- type LogConfig
- type Logger
- func (l *Logger) Alert(fmt string, args ...interface{})
- func (l *Logger) Close()
- func (l *Logger) Critical(fmt string, args ...interface{})
- func (l *Logger) Debug(fmt string, args ...interface{})
- func (l *Logger) Emergency(fmt string, args ...interface{})
- func (l *Logger) Error(fmt string, args ...interface{})
- func (l *Logger) Info(fmt string, args ...interface{})
- func (l *Logger) Notice(fmt string, args ...interface{})
- func (l *Logger) Register(w Writer)
- func (l *Logger) SetLayout(layout string)
- func (l *Logger) SetLevel(lvl int)
- func (l *Logger) Warn(fmt string, args ...interface{})
- func (l *Logger) WithFullPath(show bool)
- func (l *Logger) WithFuncName(show bool)
- type Record
- type Rotater
- type Writer
Constants ¶
const ( WriterNameConsole = "console_writer" WriterNameFile = "file_writer" WriterNameKafka = "kafka_writer" )
const ( LevelFlagEmergency = "EMERGENCY" LevelFlagAlert = "ALERT" LevelFlagCritical = "CRITICAL" LevelFlagError = "ERROR" LevelFlagWarning = "WARNING" // compatible WARN LevelFlagWarn = "WARN" LevelFlagNotice = "NOTICE" LevelFlagInfo = "INFO" LevelFlagDebug = "DEBUG" )
LevelFlag log level flags
const ( EMERGENCY = iota // Emergency: system is unusable ALERT // Alert: action must be taken immediately CRITICAL // Critical: critical conditions ERROR // Error: error conditions WARNING // Warning: warning conditions NOTICE // Notice: normal but significant condition INFO // Informational: informational messages DEBUG // Debug: debug-level messages )
RFC5424 log message levels. ref: https://tools.ietf.org/html/draft-ietf-syslog-protocol-23
Variables ¶
var ( LevelFlags = []string{ LevelFlagEmergency, LevelFlagAlert, LevelFlagCritical, LevelFlagError, LevelFlagWarning, LevelFlagNotice, LevelFlagInfo, LevelFlagDebug, } DefaultLayout = defaultLayout )
LevelFlags level Flags set
var GlobalLevel = DEBUG
GlobalLevel global level
Functions ¶
func SetLayout ¶
func SetLayout(layout string)
SetLayout set the logger time layout, should call before logger real use
func SetLevel ¶
func SetLevel(lvl int)
SetLevel set the logger level, should call before logger real use
func SetLogWithConf ¶
SetLogWithConf setup log with config file
func WithFullPath ¶
func WithFullPath(show bool)
WithFullPath set the logger with full path, should call before logger real use
func WithFuncName ¶
func WithFuncName(show bool)
WithFuncName set the logger with func name, should call before logger real use
Types ¶
type ConsoleWriter ¶
type ConsoleWriter struct {
// contains filtered or unexported fields
}
ConsoleWriter console writer define
func NewConsoleWriter ¶
func NewConsoleWriter() *ConsoleWriter
NewConsoleWriter create new console writer
func NewConsoleWriterWithOptions ¶
func NewConsoleWriterWithOptions(options ConsoleWriterOptions) *ConsoleWriter
NewConsoleWriterWithOptions create new console writer with level
func (*ConsoleWriter) Init ¶
func (w *ConsoleWriter) Init() error
Init console init without implement
func (*ConsoleWriter) SetColor ¶
func (w *ConsoleWriter) SetColor(c bool)
SetColor console output color control
func (*ConsoleWriter) SetFullColor ¶
func (w *ConsoleWriter) SetFullColor(c bool)
SetFullColor console output full line color control
type ConsoleWriterOptions ¶
type ConsoleWriterOptions struct { Enable bool `json:"enable" mapstructure:"enable"` Color bool `json:"color" mapstructure:"color"` FullColor bool `json:"full_color" mapstructure:"full_color"` Level string `json:"level" mapstructure:"level"` }
ConsoleWriterOptions color field options
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter file writer for log record deal
func NewFileWriterWithOptions ¶
func NewFileWriterWithOptions(options FileWriterOptions) *FileWriter
NewFileWriterWithOptions create new file writer with options
func (*FileWriter) Flush ¶
func (w *FileWriter) Flush() error
Flush writes any buffered data to file
func (*FileWriter) SetPathPattern ¶
func (w *FileWriter) SetPathPattern(pattern string) error
SetPathPattern for file writer
type FileWriterOptions ¶
type FileWriterOptions struct { Level string `json:"level" mapstructure:"level"` Filename string `json:"filename" mapstructure:"filename"` Enable bool `json:"enable" mapstructure:"enable"` Rotate bool `json:"rotate" mapstructure:"rotate"` // Rotate daily Daily bool `json:"daily" mapstructure:"daily"` // Rotate hourly Hourly bool `json:"hourly" mapstructure:"hourly"` // Rotate minutely Minutely bool `json:"minutely" mapstructure:"minutely"` MaxDays int `json:"max_days" mapstructure:"max_days"` MaxHours int `json:"max_hours" mapstructure:"max_hours"` MaxMinutes int `json:"max_minutes" mapstructure:"max_minutes"` }
FileWriterOptions file writer options
type KafKaMSGFields ¶
type KafKaMSGFields struct { ESIndex string `json:"es_index" mapstructure:"es_index"` // optional, init field, can set if want send data to es Level string `json:"level"` // dynamic, set by logger, mark the record level File string `json:"file"` // source code file:line_number Message string `json:"message"` // required, dynamic ServerIP string `json:"server_ip"` // required, init field, set by app Timestamp string `json:"timestamp"` // required, dynamic, set by logger Now int64 `json:"now"` // choice ExtraFields map[string]interface{} `json:"extra_fields" mapstructure:"extra_fields"` // extra fields will be added }
KafKaMSGFields kafka msg fields
type KafKaWriter ¶
type KafKaWriter struct {
// contains filtered or unexported fields
}
KafKaWriter kafka writer
func NewKafKaWriter ¶
func NewKafKaWriter(options KafKaWriterOptions) *KafKaWriter
NewKafKaWriter new kafka writer
type KafKaWriterOptions ¶
type KafKaWriterOptions struct { Enable bool `json:"enable" mapstructure:"enable"` Debug bool `json:"debug" mapstructure:"debug"` // if true, will output the send msg SpecifyVersion bool `json:"specify_version" mapstructure:"specify_version"` // if use the input version, default false ProducerReturnSuccesses bool `json:"producer_return_successes" mapstructure:"producer_return_successes"` BufferSize int `json:"buffer_size" mapstructure:"buffer_size"` Level string `json:"level" mapstructure:"level"` VersionStr string `json:"version" mapstructure:"version"` // used to specify the kafka version, ex: 0.10.0.1 or 1.1.1 Key string `json:"key" mapstructure:"key"` // kafka producer key, choice field ProducerTopic string `json:"producer_topic" mapstructure:"producer_topic"` ProducerTimeout time.Duration `json:"producer_timeout" mapstructure:"producer_timeout"` Brokers []string `json:"brokers" mapstructure:"brokers"` MSG KafKaMSGFields `json:"msg"` }
KafKaWriterOptions kafka writer options
type LogConfig ¶
type LogConfig struct { Level string `json:"level" mapstructure:"level"` Debug bool `json:"debug" mapstructure:"debug"` // output log info or not for log4go FullPath bool `json:"full_path" mapstructure:"full_path"` ConsoleWriter ConsoleWriterOptions `json:"console_writer" mapstructure:"console_writer"` FileWriter FileWriterOptions `json:"file_writer" mapstructure:"file_writer"` KafKaWriter KafKaWriterOptions `json:"kafka_writer" mapstructure:"kafka_writer"` }
LogConfig log config
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger logger define
func (*Logger) Register ¶
Register register writer the writer should be register once for writers by kind
func (*Logger) WithFullPath ¶
WithFullPath set the logger with full path
func (*Logger) WithFuncName ¶
WithFuncName set the logger with func name