Documentation
¶
Index ¶
- Constants
- func LevelToString(level int) string
- func StringToLevel(level string) int
- type Console
- type File
- func (f *File) Flush(final bool)
- func (f *File) Init()
- func (f *File) Process(item *LogItem)
- func (f *File) SetFilePath(filePath string)
- func (f *File) SetLogFormatter(s string)
- func (f *File) SetMaxBufferByte(maxBufferByte int)
- func (f *File) SetMaxBufferLine(maxBufferLine int)
- func (f *File) SetMaxLogFile(maxLogFile int)
- func (f *File) SetRotate(rotate string)
- type IFormatter
- type ILogger
- type ITarget
- type Log
- func (d *Log) Flush()
- func (d *Log) Init()
- func (d *Log) Logger(name, logId string) *Logger
- func (d *Log) Profiler() *Profiler
- func (d *Log) SetChanLen(len int)
- func (d *Log) SetFlushInterval(v string)
- func (d *Log) SetLevels(v interface{})
- func (d *Log) SetTarget(name string, target ITarget)
- func (d *Log) SetTargets(targets map[string]interface{})
- func (d *Log) SetTraceLevels(v interface{})
- func (d *Log) Target(name string) ITarget
- type LogItem
- type Logger
- func (l *Logger) Debug(format string, v ...interface{})
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) Fatal(format string, v ...interface{})
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Init(name, logId string, log *Log)
- func (l *Logger) LogId() string
- func (l *Logger) Notice(format string, v ...interface{})
- func (l *Logger) SetLogId(v string)
- func (l *Logger) Warn(format string, v ...interface{})
- type Profiler
- func (p *Profiler) Counting(key string, hit, total int)
- func (p *Profiler) CountingString() string
- func (p *Profiler) ProfileAdd(key string, elapse time.Duration)
- func (p *Profiler) ProfileStart(key string)
- func (p *Profiler) ProfileStop(key string)
- func (p *Profiler) ProfileString() string
- func (p *Profiler) PushLog(key string, v interface{})
- func (p *Profiler) PushLogString() string
- func (p *Profiler) Reset()
- func (p *Profiler) SetProfileEnable(v bool)
- type Target
Constants ¶
const ( LevelNone = 0x00 LevelDebug = 0x01 LevelInfo = 0x02 LevelNotice = 0x04 LevelWarn = 0x08 LevelError = 0x10 LevelFatal = 0x20 LevelAll = 0xFF TargetConsole = "console" TargetFile = "file" SkipKey = "__" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type File ¶
type File struct { Target // contains filtered or unexported fields }
func (*File) Process ¶
Process check and rotate log file if rotate is enable, write log to buffer, flush buffer to file if buffer is full.
func (*File) SetFilePath ¶
SetFilePath set file path, default "@runtime/app.log"
func (*File) SetLogFormatter ¶ added in v0.1.133
SetLogFormatter set formatter - json for JSON formmatter
func (*File) SetMaxBufferByte ¶
SetMaxBufferByte set max buffer bytes, default 10MB
func (*File) SetMaxBufferLine ¶
SetMaxBufferLine set max buffer lines, default 10000
func (*File) SetMaxLogFile ¶
SetMaxLogFile set max log backups, default 10
type IFormatter ¶
var ( // JSONFormatter log JSON formatter JSONFormatter IFormatter = jsonFormatter{} // JSONAccessFormatter access log with JSON formatter JSONAccessFormatter iface.IAccessLogFormat = jsonAccessFormatter{} )
type ITarget ¶
type ITarget interface { SetLevels(v interface{}) SetFormatter(v interface{}) IsHandling(level int) bool Format(item *LogItem) string Process(item *LogItem) Flush(final bool) }
func NewConsole ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func NewLog ¶
Log the log component, configuration: log:
levels: "ALL" traceLevels: "DEBUG" chanLen: 1000 flushInterval: "60s" targets: info: name: "file" levels: "DEBUG,INFO,NOTICE" filePath: "@runtime/info.log" maxLogFile: 10 rotate: "daily" error: { name: "file" levels: "WARN,ERROR,FATAL" filePath: "@runtime/error.log" maxLogFile: 10 rotate: "daily"
func (*Log) SetChanLen ¶
SetChanLen set length of log channel, default 1000
func (*Log) SetFlushInterval ¶
SetFlushInterval set interval to flush log, default "60s"
func (*Log) SetLevels ¶
func (d *Log) SetLevels(v interface{})
SetLevels set levels to handle, default "ALL"
func (*Log) SetTargets ¶
SetTargets set output target, ConsoleTarget will be used if no targets specified
func (*Log) SetTraceLevels ¶
func (d *Log) SetTraceLevels(v interface{})
SetTraceLevels set levels to trace, default "DEBUG"
type LogItem ¶
type LogItem struct { When time.Time Level int Name string LogId string Trace string Message string }
LogItem represent an item of log
type Profiler ¶
type Profiler struct { ProfileEnable bool // contains filtered or unexported fields }
Profiler
func NewProfiler ¶
func NewProfiler() *Profiler
func (*Profiler) Counting ¶
Counting add counting info, the counting string is key=sum(hit)/sum(total)
func (*Profiler) CountingString ¶
GetCountingString get counting info string
func (*Profiler) ProfileAdd ¶
ProfileAdd add profile info, the profile string is key=sum(elapse)/count
func (*Profiler) ProfileStart ¶
ProfileStart mark start of profile
func (*Profiler) ProfileStop ¶
ProfileStop mark stop of profile
func (*Profiler) ProfileString ¶
GetProfileString get profile info string
func (*Profiler) PushLogString ¶
GetPushLogString get push log string
func (*Profiler) SetProfileEnable ¶ added in v0.1.120
SetEnable log switch
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target base class of output
func (*Target) IsHandling ¶
IsHandling check whether this target is handling the log item
func (*Target) SetFormatter ¶
func (t *Target) SetFormatter(v interface{})
SetFormatter set user-defined log formatter, eg. "Lib/Log/Formatter"