代码拉取完成,页面将自动刷新
同步操作将从 phachon/go-logger 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package go_logger
import (
"testing"
"time"
)
func TestNewAdapterFile(t *testing.T) {
NewAdapterFile()
}
func TestAdapterFile_Name(t *testing.T) {
fileAdapter := NewAdapterFile()
if fileAdapter.Name() != FILE_ADAPTER_NAME {
t.Error("file adapter name error")
}
}
func TestAdapterFile_Write(t *testing.T) {
fileAdapter := NewAdapterFile()
fileConfig := &FileConfig{
Filename: "./test.log",
LevelFileName: map[int]string{
},
MaxLine:2000,
MaxSize: 10000*4,
JsonFormat:true,
DateSlice:"d",
}
err := fileAdapter.Init(fileConfig)
if err != nil {
t.Fatal(err.Error())
}
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 test file adapter write",
File : "file_test.go",
Line : 50,
Function: "TestAdapterFile_Write",
}
err = fileAdapter.Write(loggerMsg)
if err != nil {
t.Error(err.Error())
}
}
func TestAdapterFile_WriteLevelFile(t *testing.T) {
fileAdapter := NewAdapterFile()
fileConfig := &FileConfig{
Filename: "./test.log",
LevelFileName: map[int]string{
LOGGER_LEVEL_DEBUG: "./debug.log",
LOGGER_LEVEL_INFO: "./info.log",
LOGGER_LEVEL_ERROR: "./error.log",
},
MaxLine:2000,
MaxSize: 10000*4,
JsonFormat:true,
DateSlice:"d",
}
err := fileAdapter.Init(fileConfig)
if err != nil {
t.Fatal(err.Error())
}
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 test file adapter write",
File : "file_test.go",
Line : 50,
Function: "TestAdapterFile_Write",
}
fileAdapter.Write(loggerMsg)
loggerMsg.Level = LOGGER_LEVEL_INFO
fileAdapter.Write(loggerMsg)
loggerMsg.Level = LOGGER_LEVEL_ERROR
fileAdapter.Write(loggerMsg)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。