Documentation ¶
Index ¶
- Constants
- Variables
- func AddAppender(appender *Appender)
- func AddFilter(level Level, path string, timeFormat string, format string, out io.Writer)
- func ClearFilter()
- func CreateLoggerAdapter(level Level, timeFormat string, format string, out io.Writer) *log.Logger
- func Debug(format string, v ...interface{}) string
- func Error(format string, v ...interface{}) string
- func Info(format string, v ...interface{}) string
- func InitLogger()
- func Printf(logLevel Level, codeLevel int, format string, v ...interface{}) string
- func SetDefaultLevel(path string, level Level)
- func Trace(format string, v ...interface{}) string
- func WaitToClose()
- func Warn(format string, v ...interface{}) string
- type Appender
- type Config
- type FileLogConfig
- type FileLogRotatePolicy
- type FileLogWriter
- type Flusher
- type Level
- type Logger
- type SizeRotatePolicy
- type TimeRotatePolicy
Constants ¶
View Source
const ( //AdapterConsole 适配定义,控制台方式 AdapterConsole = "console" //AdapterFile 适配定义,文件方式 AdapterFile = "file" )
View Source
const ( FormatTime = "%T" //显示时间 FormatLevel = "%L" //显示级别 FormatCodeInfo = "%C" //显示代码详情 FormatMessage = "%M" //显示日志消息 )
日志格式定义
View Source
const ( // LevelError Error level LevelError Level = 1 << 0 // LevelWarn Warn level LevelWarn Level = 1<<1 | LevelError //LevelInfo Info level LevelInfo Level = 1<<2 | LevelWarn // LevelDebug Debug level LevelDebug Level = 1<<3 | LevelInfo // LevelTrace Trace level LevelTrace Level = 1<<4 | LevelDebug // FromatTimeSecond 显示格式为2006-01-02 15:04:05 FromatTimeSecond string = "2006-01-02 15:04:05" // FormatTimeNanosecond 显示格式为2006-01-02 15:04:05.999999999 FormatTimeNanosecond string = "2006-01-02 15:04:05.999999999" // FormatTimeAll 显示格式为2006-01-02 15:04:05.999999999 -0700 UTC FormatTimeAll string = "2006-01-02 15:04:05.999999999 -0700 UTC" )
Variables ¶
View Source
var ( //DefaultLevel 默认的日志级别 DefaultLevel = "error" //DefaultBufsize 日志缓冲区默认大小 DefaultBufsize = 1024 //DefaultTimeout 默认超时时间 DefaultTimeout = time.Second * 1 )
Functions ¶
func CreateLoggerAdapter ¶
CreateLoggerAdapter 创建 *log.Logger 的适配器
func SetDefaultLevel ¶
SetDefaultLevel 设置对应路径下默认的日志级别,可动态调整日志级别
Types ¶
type Appender ¶
type Appender struct { Level string `yaml:"level"` //日志级别 PackagePath string `yaml:"package_path"` //日志路径 Adapter string `yaml:"adapter"` //适配器,console,file两种 Rotate int `yaml:"rotate"` //日志切割个数 RotatePolicy string `yaml:"rotate_policy"` //切割策略,time or size or default RotateScope int64 `yaml:"rotate_scope"` //切割范围:如果按时间切割则表示的n分钟,如果是size这表示的是文件大小MB LogPath string `yaml:"log_path"` //如果适配器使用的file则用来指定文件路径 Timeformat string `yaml:"timeformat"` //指定时间输出格式.默认:"2006-01-02 15:04:05" Format string `yaml:"format"` //日志格式 }
Appender 日志处理机
type Config ¶
type Config struct { //配置上下文 Context string `yaml:"context"` //指定的日志处理机 Appenders []*Appender `yaml:"appenders"` }
Config 日志配置
type FileLogConfig ¶
type FileLogConfig struct { Path string //匹配路径 Timeformat string //时间格式 Format string Rotate int //rotate备份个数 StorePath string //日志存放路径,如:/log/test/log.log RotatePolicy FileLogRotatePolicy //循环策略 Level Level //日志级别 // contains filtered or unexported fields }
FileLogConfig 文件日志配置
type FileLogRotatePolicy ¶
type FileLogRotatePolicy interface { //是否需要循环分割 CanRotate(fileLogWriter *FileLogWriter) bool //循环风格的后置处理 RotateAfter() }
FileLogRotatePolicy 文件日志循环策略
type FileLogWriter ¶
type FileLogWriter struct {
// contains filtered or unexported fields
}
FileLogWriter 文件日志Writer封装
type Logger ¶
type Logger interface { Trace(format string, v ...interface{}) string Debug(format string, v ...interface{}) string Info(format string, v ...interface{}) string Warn(format string, v ...interface{}) string Error(format string, v ...interface{}) string }
Logger 日志接口
type SizeRotatePolicy ¶
type SizeRotatePolicy struct {
// contains filtered or unexported fields
}
SizeRotatePolicy 按文件大小的循环日志的策略
func NewSizeRotatePolicy ¶
func NewSizeRotatePolicy(maxBytes int64) *SizeRotatePolicy
NewSizeRotatePolicy 创建一个按大小循环的策略
func (*SizeRotatePolicy) CanRotate ¶
func (policy *SizeRotatePolicy) CanRotate(fileLogWriter *FileLogWriter) bool
CanRotate 判断文件是否到最大限制大小
func (*SizeRotatePolicy) RotateAfter ¶
func (*SizeRotatePolicy) RotateAfter()
RotateAfter 在循环截断后的处理,未实现
type TimeRotatePolicy ¶
type TimeRotatePolicy struct {
// contains filtered or unexported fields
}
TimeRotatePolicy 按时间循环日志的策略
func NewTimeRotatePolicy ¶
func NewTimeRotatePolicy(delay time.Duration) *TimeRotatePolicy
NewTimeRotatePolicy 创建信的按时间循环日志的策略
func (*TimeRotatePolicy) CanRotate ¶
func (policy *TimeRotatePolicy) CanRotate(fileLogWriter *FileLogWriter) bool
CanRotate 判断文件是否能 Rotate
func (*TimeRotatePolicy) RotateAfter ¶
func (policy *TimeRotatePolicy) RotateAfter()
RotateAfter 在循环截断后的处理
Click to show internal directories.
Click to hide internal directories.