refactor:log包增加处理机制

This commit is contained in:
Mmx
2021-05-05 10:46:04 +08:00
parent 9c274d4364
commit 4e4cdd35c2
6 changed files with 66 additions and 25 deletions

39
Util/log.go Normal file
View File

@@ -0,0 +1,39 @@
package Util
import (
"Mmx/Global"
"fmt"
"log"
"reflect"
)
type loG struct{}
var Log loG
func (loG) WriteLog(name string, a ...interface{}) {
for _, v := range a {
var t string
switch reflect.TypeOf(v).Kind() {
case reflect.String:
t = v.(string)
case reflect.Interface:
t = v.(error).Error()
default:
t = fmt.Sprint(v)
}
_ = File.Add(name, t)
}
}
func (c loG) Println(a ...interface{}) {
if Global.Config.Settings.DemoMode {
c.WriteLog("Login.loG", a...)
}
log.Println(a...)
}
func (c loG) Fatalln(a ...interface{}) {
c.WriteLog("LoginError.loG", a...)
log.Fatalln(a...)
}