Documentation ¶
Index ¶
- Constants
- func Debug(text string)
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(text string)
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(text string)
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Info(text string)
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Log(lv Level, text string)
- func LogDepth(calldepth int, lv Level, text string)
- func LogDepthf(calldepth int, lv Level, format string, args ...interface{})
- func LogDepthln(calldepth int, lv Level, args ...interface{})
- func Logf(lv Level, format string, args ...interface{})
- func Logln(lv Level, args ...interface{})
- func SetLevelName(f Level2Str)
- func SetLevelParse(f Str2Level)
- func SetLogger(logger Logger)
- func Warn(text string)
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- type AFormatter
- type FileCut
- type Filer
- type FilerOption
- type Formatter
- type FormatterOption
- type Level
- type Level2Str
- type Levels
- type LogOption
- type LogWriter
- type Logger
- type MultiWriter
- type MutexWriter
- func (w *MutexWriter) GetLevels() Levels
- func (w *MutexWriter) IsWrite(lv Level) bool
- func (w *MutexWriter) SetErrHandler(eh WriterErrHandler)
- func (w *MutexWriter) SetLevels(lvs Levels)
- func (w *MutexWriter) WithWriter(writer io.Writer)
- func (w *MutexWriter) Write(content []byte) (int, error)
- func (w *MutexWriter) WriteLog(lv Level, content []byte)
- type PipeWriter
- func (w *PipeWriter) GetLevels() Levels
- func (w *PipeWriter) IsWrite(lv Level) bool
- func (w *PipeWriter) SetErrHandler(eh WriterErrHandler)
- func (w *PipeWriter) SetLevels(lvs Levels)
- func (w *PipeWriter) WithWriter(writer io.Writer)
- func (w *PipeWriter) Write(content []byte) (int, error)
- func (w *PipeWriter) WriteLog(lv Level, content []byte)
- type Properties
- type SingleWriter
- type SingleWriterOption
- type Str2Level
- type WriterErrHandler
Constants ¶
View Source
const ( CUTDUR_M time.Duration = time.Minute CUTDUR_M5 = time.Minute * 5 CUTDUR_M10 = time.Minute * 10 CUTDUR_M15 = time.Minute * 15 CUTDUR_M20 = time.Minute * 20 CUTDUR_M30 = time.Minute * 30 CUTDUR_H = time.Hour CUTDUR_H2 = time.Hour * 2 CUTDUR_H3 = time.Hour * 3 CUTDUR_H4 = time.Hour * 4 CUTDUR_H6 = time.Hour * 6 CUTDUR_H8 = time.Hour * 8 CUTDUR_H12 = time.Hour * 12 //以下遇每月1号分割 CUTDUR_D = time.Hour * 24 //每1天分割,取值范围[1D,2D) CUTDUR_D2 = CUTDUR_D * 2 //每2天分割,取值范围[2D,3D) CUTDUR_D3 = CUTDUR_D * 3 //每3天分割,取值范围[3D,4D) CUTDUR_D4 = CUTDUR_D * 4 //每4天分割,取值范围[4D,5D) CUTDUR_D5 = CUTDUR_D * 5 //每5天分割,取值范围[5D,6D) // CUTDUR_D6 = 1 //按周分割,从日志开始记录按周分割,取值范围[6D,7D) CUTDUR_D7 = CUTDUR_D * 7 //按周分割,每周一进行分割,取值范围[7D,8D) CUTDUR_D8 = 2 //按周分割,每周六进行分割,取值范围[8D,9D) CUTDUR_D9 = 3 //按周分割,每周天进行分割,取值范围[9D,10D) CUTDUR_D10 = CUTDUR_D * 10 //按旬分割,每月1号11号21号进行分割,取值范围[10D,15D) CUTDUR_D15 = CUTDUR_D * 15 //按半月分割,每月1号16号进行分割,取值范围[16D,28D) CUTDUR_D30 = CUTDUR_D * 30 //按月分割,取值范围[28D,90D) CUTDUR_Q = CUTDUR_D30 * 3 //按季分割,取值范围[90D,180D) CUTDUR_Q2 = CUTDUR_Q * 2 //按半年分割,取整范围[180D,360D) CUTDUR_Y = CUTDUR_Q * 4 //按年分割,取整范围[360D,+∞) )
按时间分割日志
View Source
const ( Lv_Fatal Level = FATAL Lv_Error = Lv_Fatal | ERROR Lv_Warn = Lv_Error | WARN Lv_Info = Lv_Warn | INFO Lv_Debug = Lv_Info | DEBUG )
View Source
const DefaultDatetimeLayout = "2006-01-02T15:04:05.000"
View Source
const DefaultMaxSize = 100 * 1024 * 1024 //100M
View Source
const FilenameLayout = "20060102150405"
Variables ¶
This section is empty.
Functions ¶
func LogDepthln ¶
func SetLevelName ¶
func SetLevelName(f Level2Str)
func SetLevelParse ¶
func SetLevelParse(f Str2Level)
Types ¶
type AFormatter ¶
type AFormatter struct {
// contains filtered or unexported fields
}
func NewFormatter ¶
func NewFormatter(opts ...FormatterOption) *AFormatter
type Filer ¶
type Filer struct {
// contains filtered or unexported fields
}
func NewFiler ¶
func NewFiler(opts ...FilerOption) (*Filer, error)
type FilerOption ¶
type FilerOption func(*Filer)
func FileExt ¶
func FileExt(ext string) FilerOption
func FileRoot ¶
func FileRoot(p string) FilerOption
type Formatter ¶
type Formatter interface { //calldepth 调用层数,需要展示的最顶层第0层 //buf 外部缓存区,可以传nil //lv 日志类型 //后面包含日志参数 //返回日志填充的缓存 Sprint(calldepth int, buf []byte, lv Level, text string) []byte Sprintln(calldepth int, buf []byte, lv Level, args ...interface{}) []byte Sprintf(calldepth int, buf []byte, lv Level, format string, args ...interface{}) []byte }
type FormatterOption ¶
type FormatterOption func(*AFormatter)
func FDatetimeLayout ¶
func FDatetimeLayout(layout string) FormatterOption
func FLineFeed ¶
func FLineFeed() FormatterOption
func FMsgprefix ¶
func FMsgprefix(s string) FormatterOption
func FProperties ¶
func FProperties(p Properties) FormatterOption
type LogWriter ¶
type Logger ¶
type Logger interface { //标准接口 Log(lv Level, text string) Logln(lv Level, args ...interface{}) Logf(lv Level, format string, args ...interface{}) //自定义calldepth,顶层从0开始计算 LogDepth(calldepth int, lv Level, text string) LogDepthln(calldepth int, lv Level, args ...interface{}) LogDepthf(calldepth int, lv Level, format string, args ...interface{}) }
日志接口定义
type MultiWriter ¶
type MultiWriter struct {
// contains filtered or unexported fields
}
多个输出终端
func NewMultiWriter ¶
func NewMultiWriter(ws ...LogWriter) *MultiWriter
func (*MultiWriter) GetLevels ¶
func (w *MultiWriter) GetLevels() Levels
func (*MultiWriter) IsWrite ¶
func (w *MultiWriter) IsWrite(lv Level) bool
func (*MultiWriter) WriteLog ¶
func (w *MultiWriter) WriteLog(lv Level, content []byte)
type MutexWriter ¶
type MutexWriter struct {
// contains filtered or unexported fields
}
加锁输出
func NewMutexWriter ¶
func NewMutexWriter(opts ...SingleWriterOption) *MutexWriter
func (*MutexWriter) GetLevels ¶
func (w *MutexWriter) GetLevels() Levels
func (*MutexWriter) IsWrite ¶
func (w *MutexWriter) IsWrite(lv Level) bool
func (*MutexWriter) SetErrHandler ¶
func (w *MutexWriter) SetErrHandler(eh WriterErrHandler)
func (*MutexWriter) SetLevels ¶
func (w *MutexWriter) SetLevels(lvs Levels)
func (*MutexWriter) WithWriter ¶
func (w *MutexWriter) WithWriter(writer io.Writer)
func (*MutexWriter) WriteLog ¶
func (w *MutexWriter) WriteLog(lv Level, content []byte)
type PipeWriter ¶
type PipeWriter struct {
// contains filtered or unexported fields
}
异步输出终端
func NewPipeWriter ¶
func NewPipeWriter(opts ...SingleWriterOption) *PipeWriter
func (*PipeWriter) GetLevels ¶
func (w *PipeWriter) GetLevels() Levels
func (*PipeWriter) IsWrite ¶
func (w *PipeWriter) IsWrite(lv Level) bool
func (*PipeWriter) SetErrHandler ¶
func (w *PipeWriter) SetErrHandler(eh WriterErrHandler)
func (*PipeWriter) SetLevels ¶
func (w *PipeWriter) SetLevels(lvs Levels)
func (*PipeWriter) WithWriter ¶
func (w *PipeWriter) WithWriter(writer io.Writer)
func (*PipeWriter) WriteLog ¶
func (w *PipeWriter) WriteLog(lv Level, content []byte)
type Properties ¶
type Properties uint
properties
const ( Ldatetime Properties = 1 << iota // the date in the local time zone: 2006-01-02 LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone Llevel // the level of the log Lhostname // 主机名 Luser // 当前用户 Lfunc // full file name and line number: gitee.com/a/b.c:23 LineFeed // End with newline LstdFlags = Ldatetime | Llevel | Lfunc // initial values for the standard logger )
func (Properties) Enable ¶
func (x Properties) Enable(y Properties) bool
func (*Properties) Remove ¶
func (x *Properties) Remove(y Properties)
type SingleWriter ¶
type SingleWriter interface { SetLevels(lvs Levels) WithWriter(writer io.Writer) SetErrHandler(eh WriterErrHandler) }
type SingleWriterOption ¶
type SingleWriterOption func(SingleWriter)
func SWErrHandler ¶
func SWErrHandler(eh WriterErrHandler) SingleWriterOption
func SWLevel ¶
func SWLevel(lv Levels) SingleWriterOption
func SWStrLevel ¶
func SWStrLevel(lv string) SingleWriterOption
func SWithWriter ¶
func SWithWriter(writer io.Writer) SingleWriterOption
type WriterErrHandler ¶
Click to show internal directories.
Click to hide internal directories.