修改开发/测试环境写日志方式

This commit is contained in:
余 欣怀 2023-03-14 12:06:10 +08:00
parent 30b584f0bd
commit 33161d92ac
3 changed files with 20 additions and 14 deletions

8
log.go
View File

@ -141,6 +141,12 @@ func init() {
}
defaultModeMapping["es"] = []AdapterTupple{{level, AdapterConsole}, {level, AdapterElasticSearch}}
defaultModeMapping["ali"] = []AdapterTupple{{level, AdapterConsole}, {level, AdapterAliLs}}
defaultModeMapping[""] = []AdapterTupple{{level, AdapterConsole}, {level, AdapterFile}}
defaultModeMapping["ali"] = []AdapterTupple{{level, AdapterConsole}}
env := os.Getenv(envKey)
if env == "production" || env == "gray" || os.Getenv("GRLOG_INTERNET") == "public" {
defaultModeMapping["ali"] = append(defaultModeMapping["ali"], AdapterTupple{level, AdapterAliLs})
} else {
defaultModeMapping["ali"] = append(defaultModeMapping["ali"], AdapterTupple{level, AdapterFile})
}
}

View File

@ -63,12 +63,11 @@ func TestDropAdapter(t *testing.T) {
}
func TestNew(t *testing.T) {
os.Setenv("GRLOG_INTERNET", "public")
os.Setenv("GAORE_ENVIRONMENT", "development")
os.Setenv("CENTER_RUNMODE", "dev")
os.Setenv("GRLOG_APP_NAME", "yoda")
os.Setenv("GRLOG_ALILS_DEBUG", "on")
t.Log(os.Getenv("GRLOG_INTERNET"))
t.Log("GRLOG_INTERNET:" + os.Getenv("GRLOG_INTERNET"))
t.Log("GAORE_ENVIRONMENT:" + os.Getenv("GAORE_ENVIRONMENT"))
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)

View File

@ -81,7 +81,7 @@ func newFileWriter() Logger {
Rotate: true,
RotatePerm: "0440",
Level: LevelTrace,
Perm: "0660",
Perm: "0755",
MaxLines: 10000000,
MaxFiles: 999,
MaxSize: 1 << 28,
@ -91,15 +91,16 @@ func newFileWriter() Logger {
// Init file logger with json config.
// jsonConfig like:
// {
// "filename":"logs/beego.log",
// "maxLines":10000,
// "maxsize":1024,
// "daily":true,
// "maxDays":15,
// "rotate":true,
// "perm":"0600"
// }
//
// {
// "filename":"logs/beego.log",
// "maxLines":10000,
// "maxsize":1024,
// "daily":true,
// "maxDays":15,
// "rotate":true,
// "perm":"0600"
// }
func (w *fileLogWriter) Init(jsonConfig string) error {
err := json.Unmarshal([]byte(jsonConfig), w)
if err != nil {