This commit is contained in:
azw 2023-08-13 12:08:30 +08:00
parent f18d01d8a5
commit 01f43ab4a0
2 changed files with 15 additions and 12 deletions

View File

@ -13,7 +13,7 @@ func GetSysLog() *SysLog_ {
return _sysLog return _sysLog
} }
func GteTgLog() *TGLog_ { func GetTgLog() *TGLog_ {
return _tgLog return _tgLog
} }

View File

@ -22,6 +22,7 @@ const SYS_LOG_ROOT = "/data/logs/%s/logs/"
const SYS_LOG_FILENAME = "log_%d_%s.log" const SYS_LOG_FILENAME = "log_%d_%s.log"
type LogMsgNode struct { type LogMsgNode struct {
category int32
logMsg string logMsg string
next *LogMsgNode next *LogMsgNode
} }
@ -47,59 +48,61 @@ func (this *SysLog_) Emergency(format string, args ...interface{}) {
if this.logLevel > LOG_EMERGENCY { if this.logLevel > LOG_EMERGENCY {
return return
} }
this.addLog("[EMERGENCY]", format, args...) this.addLog(LOG_EMERGENCY, "[EMERGENCY]", format, args...)
} }
func (this *SysLog_) Alert(format string, args ...interface{}) { func (this *SysLog_) Alert(format string, args ...interface{}) {
if this.logLevel > LOG_ALERT { if this.logLevel > LOG_ALERT {
return return
} }
this.addLog("[ALERT]", format, args...) this.addLog(LOG_ALERT, "[ALERT]", format, args...)
} }
func (this *SysLog_) Error(format string, args ...interface{}) { func (this *SysLog_) Error(format string, args ...interface{}) {
if this.logLevel > LOG_ERROR { if this.logLevel > LOG_ERROR {
return return
} }
this.addLog("[ERROR]", format, args...) this.addLog(LOG_ERROR, "[ERROR]", format, args...)
} }
func (this *SysLog_) Warning(format string, args ...interface{}) { func (this *SysLog_) Warning(format string, args ...interface{}) {
if this.logLevel > LOG_WARNING { if this.logLevel > LOG_WARNING {
return return
} }
this.addLog("[WARNING]", format, args...) this.addLog(LOG_WARNING, "[WARNING]", format, args...)
} }
func (this *SysLog_) Notice(format string, args ...interface{}) { func (this *SysLog_) Notice(format string, args ...interface{}) {
if this.logLevel > LOG_NOTICE { if this.logLevel > LOG_NOTICE {
return return
} }
this.addLog("[NOTICE]", format, args...) this.addLog(LOG_NOTICE, "[NOTICE]", format, args...)
} }
func (this *SysLog_) Info(format string, args ...interface{}) { func (this *SysLog_) Info(format string, args ...interface{}) {
if this.logLevel > LOG_INFO { if this.logLevel > LOG_INFO {
return return
} }
this.addLog("[INFO]", format, args...) this.addLog(LOG_INFO, "[INFO]", format, args...)
} }
func (this *SysLog_) Debug(format string, args ...interface{}) { func (this *SysLog_) Debug(format string, args ...interface{}) {
if this.logLevel > LOG_DEBUG { if this.logLevel > LOG_DEBUG {
return return
} }
this.addLog("[DEBUG]", format, args...) this.addLog(LOG_DEBUG, "[DEBUG]", format, args...)
} }
func (this *SysLog_) addLog(category string, format string, args ...interface{}) { func (this *SysLog_) addLog(category int32, prefixStr string,
format string, args ...interface{}) {
p := &LogMsgNode{} p := &LogMsgNode{}
p.category = category
p.logMsg = time.Now().Format("2006-01-02 15:04:05") + p.logMsg = time.Now().Format("2006-01-02 15:04:05") +
category + " " + prefixStr + " " +
fmt.Sprintf(format, args...) + "\n" fmt.Sprintf(format, args...) + "\n"
/*if q5.Debug() { if category == LOG_INFO {
fmt.Print(p.logMsg) fmt.Print(p.logMsg)
}*/ }
this.msgMutex.Lock() this.msgMutex.Lock()
defer this.msgMutex.Unlock() defer this.msgMutex.Unlock()
if this.botNode != nil { if this.botNode != nil {