Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(args ...any) error
- func Debugf(format string, args ...any) error
- func Error(args ...any) error
- func Errorf(format string, args ...any) error
- func Fatal(args ...any) error
- func Fatalf(format string, args ...any) error
- func Info(args ...any) error
- func Infof(format string, args ...any) error
- func LevelString(lv Level) string
- func Log(lv Level, args ...any) error
- func LogDepth(calldepth int, lv Level, args ...any) error
- func LogDepthf(calldepth int, lv Level, format string, args ...any) error
- func LogDepthr(calldepth int, lv Level, r io.Reader) error
- func Logf(lv Level, format string, args ...any) error
- func Logr(lv Level, r io.Reader) error
- func SetLevelName(f Level2Str)
- func SetLevelParse(f Str2Level)
- func SetLogger(logger Logger)
- func Warn(args ...any) error
- func Warnf(format string, args ...any) error
- type ByteBuffer
- type BytesReader
- type FileCut
- type Filer
- type FilerOption
- type Formatter
- type FormatterOption
- type Level
- type Level2Str
- type Levels
- type LogOption
- type LogWriter
- type LogWriterOption
- type Logger
- type MultiWriter
- type PipeWriter
- type Properties
- type RingBuffer
- func (b *RingBuffer) BackWrite(size int)
- func (b *RingBuffer) Close() error
- func (b *RingBuffer) GetPos() int
- func (b *RingBuffer) Len() int
- func (b *RingBuffer) Read(buf []byte) (int, error)
- func (b *RingBuffer) ReadBytes(n int, cb func([]byte)) (int, error)
- func (b *RingBuffer) TryReadBytes(n int, cb func([]byte)) (int, error)
- func (b *RingBuffer) TryWrite(p []byte) (int, error)
- func (b *RingBuffer) Write(p []byte) (int, error)
- type Str2Level
- type TextFormatter
- func (f *TextFormatter) Sprint(calldepth int, w io.Writer, lv Level, args ...any) (int, error)
- func (f *TextFormatter) Sprintf(calldepth int, w io.Writer, lv Level, format string, args ...any) (int, error)
- func (f *TextFormatter) Sprintr(calldepth int, w io.Writer, lv Level, r io.Reader) (int, error)
- 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 Levels = 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 ¶
View Source
var (
ErrNoSpace = errors.New("no space")
)
Functions ¶
func LevelString ¶
func SetLevelName ¶
func SetLevelName(f Level2Str)
func SetLevelParse ¶
func SetLevelParse(f Str2Level)
Types ¶
type ByteBuffer ¶
type ByteBuffer []byte
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层 //w 写入接口 //lv 日志类型 //后面包含日志参数 //返回日志填充的缓存 Sprint(calldepth int, w io.Writer, lv Level, args ...any) (int, error) Sprintf(calldepth int, w io.Writer, lv Level, format string, args ...any) (int, error) Sprintr(calldepth int, w io.Writer, lv Level, r io.Reader) (int, error) }
type FormatterOption ¶
type FormatterOption func(*formatterOptions)
func FDatetimeLayout ¶
func FDatetimeLayout(layout string) FormatterOption
func FLineFeed ¶
func FLineFeed() FormatterOption
func FMsgprefix ¶
func FMsgprefix(a ...any) FormatterOption
func FProperties ¶
func FProperties(p Properties) FormatterOption
type LogOption ¶
type LogOption func(*logger)
func LogFormatter ¶
func LogMustLevels ¶
func LogSetWriter ¶
type LogWriter ¶
type LogWriter interface { io.Writer //获取可写日志类型 GetLevels() Levels //判断是否写入 IsWrite(lv Level) bool //写日志 WriteLog(lv Level, content []byte) //关闭 io.Closer }
func NewLogWriter ¶
func NewLogWriter(opts ...LogWriterOption) LogWriter
type LogWriterOption ¶
type LogWriterOption func(*logWriterOptions)
func LWErrHandler ¶
func LWErrHandler(eh WriterErrHandler) LogWriterOption
func LWLevel ¶
func LWLevel(lv Levels) LogWriterOption
func LWStrLevel ¶
func LWStrLevel(lv string) LogWriterOption
func LWithWriter ¶
func LWithWriter(writer io.Writer) LogWriterOption
type Logger ¶
type Logger interface { //标准接口 Log(lv Level, args ...any) error Logf(lv Level, format string, args ...any) error Logr(lv Level, r io.Reader) error //写大块日志 //自定义calldepth,与log库一样 LogDepth(calldepth int, lv Level, args ...any) error LogDepthf(calldepth int, lv Level, format string, args ...any) error LogDepthr(calldepth int, lv Level, r io.Reader) error //写大块日志 //关闭日志 io.Closer }
日志接口定义
type MultiWriter ¶
type MultiWriter struct {
// contains filtered or unexported fields
}
多个输出终端
func NewMultiWriter ¶
func NewMultiWriter(ws ...LogWriter) *MultiWriter
func (*MultiWriter) Close ¶
func (w *MultiWriter) Close() error
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 PipeWriter ¶
type PipeWriter struct {
// contains filtered or unexported fields
}
异步输出终端
func NewPipeWriter ¶
func NewPipeWriter(opts ...LogWriterOption) *PipeWriter
func (*PipeWriter) Close ¶
func (w *PipeWriter) Close() error
func (*PipeWriter) GetLevels ¶
func (w *PipeWriter) GetLevels() Levels
func (*PipeWriter) IsWrite ¶
func (w *PipeWriter) IsWrite(lv Level) bool
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 Lfunc // full file name and line number: gitee.com/a/b.c:23 LineFeed // End with newline LstdFlags = Ldatetime | Llevel | Lfunc | LineFeed // 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 RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
缓存器
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
func (*RingBuffer) Close ¶
func (b *RingBuffer) Close() error
func (*RingBuffer) GetPos ¶
func (b *RingBuffer) GetPos() int
func (*RingBuffer) TryReadBytes ¶
func (b *RingBuffer) TryReadBytes(n int, cb func([]byte)) (int, error)
type TextFormatter ¶
type TextFormatter struct {
// contains filtered or unexported fields
}
func NewTextFormatter ¶
func NewTextFormatter(opts ...FormatterOption) *TextFormatter
type WriterErrHandler ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.