simplelog

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 13 Imported by: 0

README

simplelog

Build Status Go Report Card codecov

特性

  • 支持格式微自定义
  • 不同错误级别写入不同文件夹
  • 单文件容量限制,切割文件
  • 文件保留时间设置,自动删除过期文件
  • 捕获堆栈信息

Usage

go get -u github.com/huzhongqing/simplelog

# please read example.

Documentation

Index

Constants

View Source
const (
	DebugLevel int = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer added in v0.2.0

type Buffer struct {
	// contains filtered or unexported fields
}

func (*Buffer) AppendString added in v0.2.0

func (b *Buffer) AppendString(v string)

func (*Buffer) Bytes added in v0.2.0

func (b *Buffer) Bytes() []byte

func (*Buffer) Len added in v0.2.0

func (b *Buffer) Len() int

func (*Buffer) Reset added in v0.2.0

func (b *Buffer) Reset()

func (*Buffer) String added in v0.2.0

func (b *Buffer) String() string

type BufferPool added in v0.2.0

type BufferPool struct {
	// contains filtered or unexported fields
}

func NewBufferPool added in v0.2.0

func NewBufferPool() BufferPool

func (BufferPool) Get added in v0.2.0

func (bp BufferPool) Get() *Buffer

func (BufferPool) Put added in v0.2.0

func (bp BufferPool) Put(buf *Buffer)

type Config

type Config struct {
	// 调用深度
	Calldpeth int
	// 日志等级,>= 设置的等级才会写入
	Level int
	// 格式化,配置
	Format *FormatConfig
	Write  *WriteConfig
}

Config 日志配置信息

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 默认配置

type Format

type Format struct {
	// contains filtered or unexported fields
}

func NewFormat

func NewFormat(cfg *FormatConfig) *Format

NewFormat

func (*Format) GenMessage

func (f *Format) GenMessage(level, message string) []byte

GenMessage 生成等待写入的内容

func (*Format) Stack

func (f *Format) Stack(msg string) string

返回当前堆栈信息

type FormatConfig

type FormatConfig struct {
	// 时间格式
	LogTimeFormat string

	// 消息前缀
	MessagePrefix string
}

FormatConfig

func DefaultFormatConfig

func DefaultFormatConfig() *FormatConfig

默认格式化配置文件

type SimpleLogger

type SimpleLogger struct {
	// contains filtered or unexported fields
}

SimpleLogger

func NewSimpleLogger

func NewSimpleLogger(cfg Config) *SimpleLogger

NewSimpleLogger new

func (*SimpleLogger) Append added in v0.2.0

func (sl *SimpleLogger) Append(message []byte) (n int, err error)

Append 写入文件

func (*SimpleLogger) Close

func (sl *SimpleLogger) Close() error

Close

func (*SimpleLogger) Debug

func (sl *SimpleLogger) Debug(format string, args ...interface{})

Debug

func (*SimpleLogger) Error

func (sl *SimpleLogger) Error(format string, args ...interface{})

Error

func (*SimpleLogger) Fatal

func (sl *SimpleLogger) Fatal(format string, args ...interface{})

Fatal 等级 退出程序

func (*SimpleLogger) Info

func (sl *SimpleLogger) Info(format string, args ...interface{})

Info

func (*SimpleLogger) Output

func (sl *SimpleLogger) Output(calldepth int, s string) (n int, err error)

Output 系统输出

func (*SimpleLogger) SetLevel

func (sl *SimpleLogger) SetLevel(level int)

SetLevel 设置错误等级

func (*SimpleLogger) Stack

func (sl *SimpleLogger) Stack(err error) string

Stack 堆栈信息

func (*SimpleLogger) String

func (sl *SimpleLogger) String(calldpeth int, level, message string) []byte

String 生成待写入文件的数据

func (*SimpleLogger) Warn

func (sl *SimpleLogger) Warn(format string, args ...interface{})

Warn

type Write

type Write struct {
	// contains filtered or unexported fields
}

Write 写入文件对象

func NewWrite

func NewWrite(cfg *WriteConfig) *Write

NewWrite new

func (*Write) Close

func (w *Write) Close() error

Close 释放

func (*Write) Sync added in v0.2.0

func (w *Write) Sync() error

func (*Write) Write added in v0.2.0

func (w *Write) Write(message []byte) (n int, err error)

type WriteConfig added in v0.3.0

type WriteConfig struct {
	// 写入文件
	Filename string
	// 单文件最大 bytes
	MaxSize int64
	// 保留文件时间
	MaxAge time.Duration
	// Gzip 压缩
	Compress bool
}

func DefaultWriteConfig added in v0.3.0

func DefaultWriteConfig() *WriteConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL