Documentation ¶
Index ¶
- Constants
- Variables
- func CallerFormat(file string, line int, funcName string) string
- func Debug(args ...interface{})
- func Debugf(fmt string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...interface{})
- func Errorf(fmt string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(fmt string, args ...interface{})
- func Fatalln(args ...interface{})
- func FramesToCaller() int
- func GetOutputBySeverity(severity Level) io.Writer
- func Info(args ...interface{})
- func Infof(fmt string, args ...interface{})
- func Infoln(args ...interface{})
- func InitOnce(logging, factory value.Value)
- func InitUnsafe(logging, factory value.Value)
- func IsEnabled(severityLevel Level) bool
- func NewDefaultFactory(opts ...LoggingOpt) *loggerFactory
- func NewFactory(logging Logging) *loggerFactory
- func NewFactoryWithValue(v value.Value) *loggerFactory
- func NewHookLevelLogging(logging Logging, hook LevelHook) *hookLevelLogging
- func NewMutableFactory(logging Logging) *mutableLoggerFactory
- func NewMutableFactoryWithValue(v value.Value) *mutableLoggerFactory
- func Panic(args ...interface{})
- func Panicf(fmt string, args ...interface{})
- func Panicln(args ...interface{})
- func ResetFactory(fac LoggerFactory)
- func ResetLogging(logging Logging)
- func SetCallerFlag(flag int) func(*logging)
- func SetCallerFormatter(f func(file string, line int, funcName string) string) func(*logging)
- func SetColorFlag(flag int) func(*logging)
- func SetExitFunc(f ExitFunc) func(*logging)
- func SetFatalNoTrace(noTrace bool) func(*logging)
- func SetFormatter(f Formatter)
- func SetOutput(w io.Writer)
- func SetOutputBySeverity(severity Level, w io.Writer)
- func SetPanicFunc(f PanicFunc) func(*logging)
- func SetSeverityLevel(severity Level)
- func SetTimeFormatter(f func(t time.Time) string) func(*logging)
- func SimplifyNameFirstLetter(s string) string
- func TimeFormat(t time.Time) string
- func Warn(args ...interface{})
- func Warnf(fmt string, args ...interface{})
- func Warnln(args ...interface{})
- func WithDepth(depth int)
- func WithFields(keyAndValues ...interface{})
- type ExitFunc
- type Formatter
- type Iterator
- type JsonFormatter
- type KeyValues
- type Level
- type LevelHook
- type LogDebug
- type LogError
- type LogFatal
- type LogInfo
- type LogPanic
- type LogWarn
- type Logger
- type LoggerFactory
- type Logging
- type LoggingOpt
- type PanicFunc
- type TextFormatter
Constants ¶
const ( //不显示调用信息 CallerNone = 0 //只显示文件名 CallerShortFile = 1 //显示文件名及路径 CallerLongFile = 1 << 1 //file mask CallerFileMask = 3 //只显示函数名 CallerShortFunc = 1 << 2 //显示完整函数名 CallerLongFunc = 1 << 3 //显示简单函数名 CallerSimpleFunc = 1 << 4 //func mask CallerFuncMask = 7 << 2 )
const ( //自动填充颜色 AutoColor = iota //禁用颜色 DisableColor //强制使用颜色 ForceColor )
const ( // 时间戳的Key KeyTimestamp = "LogTime" // 日志级别key KeySeverityLevel = "LogLevel" // 调用者Key KeyCaller = "LogCaller" // 日志内容Key KeyContent = "LogContent" // 日志名称Key KeyName = "LogName" )
Variables ¶
var ( // 默认日志深度 LogDepth value.Value = value.NewSimpleValue(int(1)) // 默认日志附加信息(无) LogFields value.Value = value.NewSimpleValue(nil) )
var ( //前景色 ColorGreen = string([]byte{27, 91, 57, 55, 59, 52, 50, 109}) ColorWhite = string([]byte{27, 91, 57, 48, 59, 52, 55, 109}) ColorYellow = string([]byte{27, 91, 57, 48, 59, 52, 51, 109}) ColorRed = string([]byte{27, 91, 57, 55, 59, 52, 49, 109}) ColorBlue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109}) ColorMagenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109}) ColorCyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109}) ColorReset = string([]byte{27, 91, 48, 109}) ForeGreen = "\033[97;32m" ForeWhite = "\033[90;37m" ForeYellow = "\033[90;33m" ForeRed = "\033[97;31m" ForeBlue = "\033[97;34m" ForeMagenta = "\033[97;35m" ForeCyan = "\033[97;36m" //背景色 BackGreen = "\033[97;42m" BackWhite = "\033[90;47m" BackYellow = "\033[90;43m" BackRed = "\033[97;41m" BackBlue = "\033[97;44m" BackMagenta = "\033[97;45m" BackCyan = "\033[97;46m" ResetColor = "\033[0m" )
var ( DefaultColorFlag = DisableColor DefaultPrintFileFlag = CallerShortFile DefaultFatalNoTrace = false DefaultLevel = INFO DefaultWriters = map[Level]io.Writer{ DEBUG: os.Stdout, INFO: os.Stdout, WARN: os.Stdout, ERROR: os.Stderr, PANIC: os.Stderr, FATAL: os.Stderr, } )
默认值
var LogTag = map[Level]string{ DEBUG: "DEBUG", INFO: "INFO", WARN: "WARN", ERROR: "ERROR", PANIC: "PANIC", FATAL: "FATAL", }
级别及名称映射
Functions ¶
func CallerFormat ¶ added in v0.0.6
func FramesToCaller ¶
func FramesToCaller() int
func GetOutputBySeverity ¶ added in v0.0.6
获得默认Logging对应日志级别的输出
func InitOnce ¶ added in v0.0.9
配置默认的Logging、Factory value(线程安全且只能初始化一次) 可以配置为线程安全(value.AtomicValue)的和非线程安全的(value.SimpleValue)
func InitUnsafe ¶ added in v0.0.9
配置默认的Logging、Factory value(非线程安全) 可以配置为线程安全(value.AtomicValue)的和非线程安全的(value.SimpleValue)
func NewDefaultFactory ¶
func NewDefaultFactory(opts ...LoggingOpt) *loggerFactory
func NewFactory ¶
func NewFactory(logging Logging) *loggerFactory
func NewFactoryWithValue ¶ added in v0.0.9
func NewHookLevelLogging ¶
func NewMutableFactory ¶ added in v0.0.8
func NewMutableFactory(logging Logging) *mutableLoggerFactory
func NewMutableFactoryWithValue ¶ added in v0.0.9
func ResetFactory ¶
func ResetFactory(fac LoggerFactory)
重新配置全局的默认LoggerFactory,该方法同时会重置全局的默认Logging 由于线程安全性受defaultLogging、defaultFactory初始化(调用InitOnce)的Value决定, 所以需要确定是否确实需要调用该方法重置Logging,并保证Value线程安全
func ResetLogging ¶ added in v0.0.9
func ResetLogging(logging Logging)
重新配置全局的默认Logging,该方法同时会重置全局的默认LoggerFactory的Logging 由于线程安全性受defaultLogging、defaultFactory初始化(调用InitOnce)的Value决定, 所以需要确定是否确实需要调用该方法重置Logging,并保证Value线程安全
func SetCallerFlag ¶ added in v0.0.6
func SetCallerFlag(flag int) func(*logging)
配置内置Logging实现的文件输出标志,有ShortFile、LongFile
func SetCallerFormatter ¶ added in v0.0.6
配置内置Logging实现的时间格式化函数
func SetColorFlag ¶
func SetColorFlag(flag int) func(*logging)
配置内置Logging实现的颜色的标志,有AutoColor、DisableColor、ForceColor
func SetExitFunc ¶ added in v0.0.6
func SetExitFunc(f ExitFunc) func(*logging)
配置内置Logging Fatal退出处理函数
func SetFatalNoTrace ¶
func SetFatalNoTrace(noTrace bool) func(*logging)
配置内置Logging实现是否在发生致命错误时打印堆栈,默认打印
func SetOutputBySeverity ¶
设置默认Logging对应日志级别的输出
func SetPanicFunc ¶ added in v0.0.7
func SetPanicFunc(f PanicFunc) func(*logging)
配置内置Logging Panic处理函数
func SetTimeFormatter ¶
配置内置Logging实现的时间格式化函数
func SimplifyNameFirstLetter ¶
func TimeFormat ¶
Types ¶
type JsonFormatter ¶
type JsonFormatter struct { }
type KeyValues ¶ added in v0.0.6
type KeyValues interface { Add(keyAndValues ...interface{}) error GetAll() map[string]interface{} Keys() []string Get(key string) interface{} Remove(key string) error Len() int Iterator() Iterator Clone() KeyValues }
func MergeKeyValues ¶ added in v0.0.6
func NewKeyValues ¶ added in v0.0.6
func NewKeyValues(keyAndValues ...interface{}) KeyValues
type Logger ¶
type Logger interface { // Debug级别日志接口 LogDebug // Info级别日志接口 LogInfo // Warn级别日志接口 LogWarn // Error级别日志接口 LogError // Panic级别日志接口,注意会触发Panic LogPanic // Fatal级别日志接口,注意会触发程序退出 LogFatal // 附加日志名称,注意会附加父Logger的名称,格式为:父Logger名称 + '.' + name WithName(name string) Logger // 附加日志信息,注意会附加父Logger的附加信息,如果相同则会覆盖 WithFields(keyAndValues ...interface{}) Logger // 配置日志的调用深度,注意会在父Logger的基础上调整深度 WithDepth(depth int) Logger }
Logger是xlog的日志封装工具,实现了常用的日志方法
type LoggerFactory ¶
type LoggerFactory interface { // 根据参数获得Logger // Param:根据默认实现,o可不填,直接返回一个没有名称的Logger。 // 如果o有值,则只取第一个值,且当: // o为string时,使用string值作为Logger名称 // o为其他类型时,取package path + type name作为Logger名称,以"."分隔,如g.x.x.t.TestStructInTest GetLogger(o ...interface{}) Logger // 重置Factory的Logging(线程安全) Reset(logging Logging) LoggerFactory // 获得Factory的Logging(线程安全),可用来配置Logging // 也可以通过wrap Logging达到控制日志级别、日志输出格式的目的 GetLogging() Logging }
type Logging ¶
type Logging interface { // 输出format日志(线程安全) // Param: level日志级别, depth调用深度, keyValues附加的日志内容(多用于添加固定的日志信息), format格式化的格式, args参数 Logf(level Level, depth int, keyValues KeyValues, format string, args ...interface{}) // 解析并输出参数(线程安全) // Param: level日志级别, depth调用深度, keyValues附加的日志内容(多用于添加固定的日志信息), args参数 Log(level Level, depth int, keyValues KeyValues, args ...interface{}) // 解析并输出参数,末尾增加换行(线程安全) // Param: level日志级别, depth调用深度, keyValues附加的日志内容(多用于添加固定的日志信息), args参数 Logln(level Level, depth int, keyValues KeyValues, args ...interface{}) // 设置日志格式化工具(线程安全) SetFormatter(f Formatter) // 设置日志严重级别,低于该级别的将不被输出(线程安全) SetSeverityLevel(severityLevel Level) // 判断参数级别是否会输出(线程安全) IsEnabled(severityLevel Level) bool // 设置输出的Writer,注意该方法会将所有级别都配置为参数writer(线程安全) SetOutput(w io.Writer) // 设置对应日志级别的Writer(线程安全) SetOutputBySeverity(severityLevel Level, w io.Writer) // 获得对应日志级别的Writer(线程安全) GetOutputBySeverity(severityLevel Level) io.Writer // 获得一个clone的对象(线程安全) Clone() Logging }
Logging是xlog的日志基础工具,向下对接日志输出Writer,向上提供日志操作接口
func NewLogging ¶
func NewLogging(opts ...LoggingOpt) Logging
type LoggingOpt ¶
type LoggingOpt func(l *logging)