代码拉取完成,页面将自动刷新
package gologger
import (
"fmt"
)
type ConsoleLogger struct {
Level LogLevel
}
//构造函数
func NewConsoleLogger(levelStr string) *ConsoleLogger {
level, err := paseLogLevel(levelStr)
if err != nil {
panic(err)
}
return &ConsoleLogger{
Level: level,
}
}
//日志开关
func (c *ConsoleLogger) enable(lv LogLevel) bool {
return lv >= c.Level
}
//格式化输出
func (c *ConsoleLogger) logFotmatOutput(lv LogLevel, fotmat string, a ...interface{}) {
if c.enable(lv) {
msg := fmt.Sprintf(fotmat, a...)
funcName, fileName, lineNo, timestamp := getInfo(3)
fmt.Printf("%s [%s] [file: %s/%s line: %d] %s \n", timestamp, getLogString(lv), funcName, fileName, lineNo, msg)
}
}
func (c *ConsoleLogger) DEBUG(fotmat string, a ...interface{}) {
c.logFotmatOutput(DEBUG, fotmat, a...)
}
func (c *ConsoleLogger) INFO(fotmat string, a ...interface{}) {
c.logFotmatOutput(INFO, fotmat, a...)
}
func (c *ConsoleLogger) WARNING(fotmat string, a ...interface{}) {
c.logFotmatOutput(WARNING, fotmat, a...)
}
func (c *ConsoleLogger) ERROR(fotmat string, a ...interface{}) {
c.logFotmatOutput(ERROR, fotmat, a...)
}
func (c *ConsoleLogger) FATAL(fotmat string, a ...interface{}) {
c.logFotmatOutput(FATAL, fotmat, a...)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。