1 Star 0 Fork 13

skymysky/go-logger

forked from phachon/go-logger 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
logger_test.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
phachon 提交于 2018-04-23 18:12 . fix
package go_logger
import (
"testing"
"time"
"fmt"
)
func TestNewLogger(t *testing.T) {
NewLogger()
}
func TestLogger_Attach(t *testing.T) {
logger := NewLogger()
fileConfig := &FileConfig{}
logger.Attach("file", LOGGER_LEVEL_DEBUG, fileConfig)
outputs := logger.outputs
for _, outputLogger := range outputs {
if outputLogger.Name != "file" {
t.Error("file attach failed")
}
}
}
func TestLogger_Detach(t *testing.T) {
logger := NewLogger()
logger.Detach("console")
outputs := logger.outputs
if len(outputs) > 0 {
t.Error("logger detach error")
}
}
func TestLogger_LoggerLevel(t *testing.T) {
logger := NewLogger()
level := logger.LoggerLevel("emerGENCY")
if level != LOGGER_LEVEL_EMERGENCY {
t.Error("logger loggerLevel error")
}
level = logger.LoggerLevel("ALERT")
if level != LOGGER_LEVEL_ALERT {
t.Error("logger loggerLevel error")
}
level = logger.LoggerLevel("cRITICAL")
if level != LOGGER_LEVEL_CRITICAL {
t.Error("logger loggerLevel error")
}
level = logger.LoggerLevel("DEBUG")
if level != LOGGER_LEVEL_DEBUG {
t.Error("logger loggerLevel error")
}
level = logger.LoggerLevel("ooox")
if level != LOGGER_LEVEL_DEBUG {
t.Error("logger loggerLevel error")
}
}
func TestLogger_loggerMessageFormat(t *testing.T) {
loggerMsg := &loggerMessage{
Timestamp : time.Now().Unix(),
TimestampFormat : time.Now().Format("2006-01-02 15:04:05"),
Millisecond : time.Now().UnixNano()/1e6,
MillisecondFormat : time.Now().Format("2006-01-02 15:04:05.999"),
Level : LOGGER_LEVEL_DEBUG,
LevelString: "debug",
Body: "logger console adapter test",
File : "console_test.go",
Line : 77,
Function: "TestAdapterConsole_WriteJsonFormat",
}
format := "%millisecond_format% [%level_string%] [%file%:%line%] %body%"
str := loggerMessageFormat(format, loggerMsg)
fmt.Println(str)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/skymysky/go-logger.git
[email protected]:skymysky/go-logger.git
skymysky
go-logger
go-logger
master

搜索帮助