QLog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT Imports: 15 Imported by: 6

README

QLog

功能
  • 设置日志输出级别debug/info/warn/error/fatal
  • 设置输出位置:文件/控制台
  • 打出日志相应文件及所在行数
  • 自定义日期格式(DateFormat)
  • 自定义单个文件大小(FileMaxSize,单位B,默认1G),当日文件info_2018-06-30.log,大于设定文件大小后,info_2018-06-30.1.log,序号依次增加
  • 支持双写(终端与文件)
  • 打出当前机器IP
  • 设置日志打印最大个数
  • 设置日志是否gip打包
  • 异步打印日志
任务
  • [ ]
使用示例

参见test/logger_test.go

Documentation

Index

Constants

View Source
const (
	DEFAULTFILENAME    = "info"  //默认文件前缀
	DEFAULTFILEPATH    = "./"    //默认文件存放路径
	DEFAULTFILESUFFIX  = "log"   //默认文件后缀
	DEFAULTFILEMAXSIZE = 2 << 29 //默认单个文件最大1G

)

默认值

View Source
const (
	ALL uint8 = iota
	DEBUG
	INFO
	WARN
	ERROR
	FATAL
	ALERT
	OFF
)
View Source
const (
	ALERTALERT    = "notice"   // notice
	ALERTWARNING  = "warning"  // 严重
	ALERTCRITICAL = "critical" // 紧急
)

alert level

View Source
const (
	DIAGONAL   = "/"
	COLON      = ":"
	BLANK      = " "
	NEWLINE    = "\n"
	DOT        = "."
	UNDERSCODE = "_"
	DASH       = "-"
)
View Source
const (
	TYPEDEBUG = "DEBUG"
	TYPEINFO  = "INFO"
	TYPEWARN  = "WARN"
	TYPEERROR = "ERROR"
	TYPEFATAL = "FATAL"
	TYPEALERT = "ALERT"
)
View Source
const (
	COLOR_RED = uint8(iota + 91)
	COLOR_GREEN
	COLOR_YELLOW
	COLOR_BLUE
	COLOR_MAGENTA //洋红
	COLOR_INTENSITY
)
View Source
const COLOR_TPL = "\x1b[%dm%s\x1b[0m"

Variables

View Source
var (
	YRDLogger    LoggerInterface
	ServerIp     string
	TimeLocation *time.Location
)

Functions

func GetCaller

func GetCaller(calldepth int) (str string)

func GetLogTextPrefix

func GetLogTextPrefix(calldepth int, format string) string

func GetNowTime

func GetNowTime(format string) (str string)

func GetNowUnixTimeOBJ

func GetNowUnixTimeOBJ() time.Time

func Itoa

func Itoa(i int, wid int) string

Types

type AlertApiConfig

type AlertApiConfig struct {
	AppId       string
	URL         string
	ContentType string
	Format      string
	IsAlert     bool
}

type ConfigOption

type ConfigOption func(*logger)

func WithAlertOPT

func WithAlertOPT(appId, URL, ContentType string) ConfigOption

报警配置

func WithCommonOPT

func WithCommonOPT(cDep int, dateFormat string) ConfigOption

func WithConsoleOPT

func WithConsoleOPT() ConfigOption

func WithFileOPT

func WithFileOPT(filepath, filename, filesuffix string, fileMaxSize int64, fileMaxNSize int) ConfigOption

func WithcallDepOPT

func WithcallDepOPT(cDep int) ConfigOption

type LoggerInterface

type LoggerInterface interface {
	SetConfig(uint8, string, ...ConfigOption)
	SetTextPrefix(...interface{})
	AddTextPrefix(...interface{})
	Debug(v ...interface{})
	Info(v ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})
	Fatal(v ...interface{})
	AlertWithLevel(alertLevel string, v ...interface{})
}

func GetLogger

func GetLogger() LoggerInterface

Jump to

Keyboard shortcuts

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