Documentation ¶
Index ¶
- Constants
- Variables
- func LogFilePath(c *Config) (filepath string)
- type AsynchronousWriter
- type BufferWriter
- type Config
- type LockedWriter
- type Manager
- type Option
- func WithAsynchronous() Option
- func WithBuffer() Option
- func WithBufferThreshold(n int) Option
- func WithCompress() Option
- func WithFileName(name string) Option
- func WithLock() Option
- func WithLogPath(path string) Option
- func WithMaxRemain(max int) Option
- func WithRollingTimePattern(pattern string) Option
- func WithRollingVolumeSize(size string) Option
- func WithTimeTagFormat(format string) Option
- func WithoutRollingPolicy() Option
- type RollingWriter
- type Writer
Constants ¶
View Source
const ( WithoutRolling = iota TimeRolling VolumeRolling )
三种滚动模式
Variables ¶
View Source
var ( BufferSize = 0x100000 QueueSize = 1024 Precision = 1 DefualtFileMode = os.FileMode(0644) DefualtFileFlag = os.O_RDWR | os.O_CREATE | os.O_APPEND // 自定义错误 ErrInternal = errors.New("error internal") ErrClosed = errors.New("error write on close") ErrInvalidArgument = errors.New("error argument invalid") )
一些默认的全局变量
Functions ¶
Types ¶
type AsynchronousWriter ¶
type AsynchronousWriter struct { Writer // contains filtered or unexported fields }
当WriterMode为async时使用的结构,同步writer,并发安全
type BufferWriter ¶
type BufferWriter struct { Writer // contains filtered or unexported fields }
当WriterMode为buffer时使用的结构,异步write, 并发安全
type Config ¶
type Config struct { TimeTagFormat string `json:"time_tag_format" yaml:"timeTagFormat"` //时间格式化结构 LogPath string `json:"log_path" yaml:"logPath"` // 日志路径 FileName string `json:"file_name" yaml:"fileName"` // 日志文件名称 MaxRemain int `json:"max_remain" yaml:"maxRemain"` // 日志文件的最大存留数 // 日志滚动策略,三个选项 // 0:WithoutRolling:,不滚动 // 1:TimeRolling,时间滚动策略, // 2:VolumeRolling,大小滚动策略 RollingPolicy int `json:"rolling_policy" yaml:"rollingPolicy"` RollingTimePattern string `json:"rolling_time_pattern" yaml:"rollingTimePattern"` // 时间滚动策略时的cron表达式 RollingVolumeSize string `json:"rolling_volume_size" yaml:"rollingVolumeSize"` // 大小滚动策略时的截断大小 WriterMode string `json:"writer_mode" yaml:"writerMode"` // none, lock, async, buffer BufferWriterThreshold int `json:"buffer_threshold" yaml:"bufferWriterThreshold"` // 一部并发是缓存池的大小 Compress bool `json:"compress" yaml:"compress"` // 是否压缩历史日志 }
type LockedWriter ¶
当WriterMode为lock时使用的结构,lock保护的writer: 提供由mutex保护的并发安全保障
type Option ¶
type Option func(*Config)
配置构造函数,用于更新配置
func WithRollingTimePattern ¶
设置为按时间滚动模式,更新滚动时间表达式
type RollingWriter ¶
func NewWriterFromConfig ¶
func NewWriterFromConfig(c *Config) (RollingWriter, error)
根据配置生成RollingWriter,用于接收日志输入
func NewWriterFromConfigFile ¶
func NewWriterFromConfigFile(path string, typ string) (RollingWriter, error)
从配置文件读取配置,解析后生成RollingWriter,支持json和yaml类型
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
当WriterMode为none时使用的结构,无保护的writer: 不提供并发安全保障
func (*Writer) CompressFile ¶
压缩历史文件
Click to show internal directories.
Click to hide internal directories.