update log format --all replace

This commit is contained in:
engigu
2024-01-13 12:04:40 +08:00
parent c0241df60c
commit e76782451b
9 changed files with 41 additions and 37 deletions
+4 -2
View File
@@ -4,9 +4,11 @@ import (
"embed"
"fmt"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"message-nest/migrate"
"message-nest/models"
"message-nest/pkg/logging"
"message-nest/pkg/setting"
"message-nest/pkg/table"
"message-nest/routers"
@@ -51,11 +53,11 @@ func GinServerUp() {
MaxHeaderBytes: maxHeaderBytes,
}
logging.Logger.Info("start http server listening http://0.0.0.0", endPoint)
logrus.Info("start http server listening http://0.0.0.0", endPoint)
err := server.ListenAndServe()
if err != nil {
logging.Logger.Error("Server err: ", err)
logrus.Error("Server err: ", err)
}
}
+2 -2
View File
@@ -3,7 +3,7 @@ package middleware
import (
"fmt"
"math"
"message-nest/pkg/logging"
"net/http"
"net/url"
"time"
@@ -53,7 +53,7 @@ func LogMiddleware(notLogged ...string) gin.HandlerFunc {
return
}
entry := logging.Logger.WithFields(logrus.Fields{
entry := logrus.WithFields(logrus.Fields{
////"hostname": hostname,
//"statusCode": statusCode,
//"latency": latency,
+5 -5
View File
@@ -4,8 +4,8 @@ import (
"errors"
"fmt"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
"message-nest/models"
"message-nest/pkg/logging"
"message-nest/pkg/setting"
)
@@ -17,7 +17,7 @@ func InitAuthTableData() {
settingO, err := models.GetSettingByKey(initSection, initAuthKey)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logging.Logger.Error(fmt.Sprintf("查询账号初始化失败!"))
logrus.Error(fmt.Sprintf("查询账号初始化失败!"))
return
}
if settingO.Value == "1" {
@@ -26,15 +26,15 @@ func InitAuthTableData() {
}
err = models.AddUser(initAccount, initAccountPasswd)
if err != nil {
logging.Logger.Error(fmt.Sprintf("添加初始化admin账号失败!"))
logrus.Error(fmt.Sprintf("添加初始化admin账号失败!"))
return
} else {
logging.Logger.Error(fmt.Sprintf("初始化admin账号成功!您的账号:%s 密码:%s", initAccount, initAccountPasswd))
logrus.Error(fmt.Sprintf("初始化admin账号成功!您的账号:%s 密码:%s", initAccount, initAccountPasswd))
}
err = models.AddOneSetting(models.Settings{Section: initSection, Key: initAuthKey, Value: "1"})
if err != nil {
logging.Logger.Error(fmt.Sprintf("标记admin账号初始化状态失败!"))
logrus.Error(fmt.Sprintf("标记admin账号初始化状态失败!"))
return
}
}
+9 -9
View File
@@ -10,7 +10,7 @@ import (
"strings"
)
var Logger = logrus.New()
//var Logger = logrus.New()
func getFuncOutStr(funcStr string) string {
parts := strings.Split(funcStr, ".")
@@ -41,21 +41,21 @@ func Setup() {
PrefixStyle: "green",
})
Logger.Formatter = formatter
Logger.SetReportCaller(true)
Logger.SetOutput(os.Stdout)
logrus.SetFormatter(formatter)
logrus.SetReportCaller(true)
logrus.SetOutput(os.Stdout)
level := strings.ToLower(setting.AppSetting.LogLevel)
switch level {
case "debug":
Logger.SetLevel(logrus.DebugLevel)
logrus.SetLevel(logrus.DebugLevel)
case "info":
Logger.SetLevel(logrus.InfoLevel)
logrus.SetLevel(logrus.InfoLevel)
case "warn":
Logger.SetLevel(logrus.WarnLevel)
logrus.SetLevel(logrus.WarnLevel)
case "error":
Logger.SetLevel(logrus.ErrorLevel)
logrus.SetLevel(logrus.ErrorLevel)
default:
Logger.SetLevel(logrus.DebugLevel)
logrus.SetLevel(logrus.DebugLevel)
}
}
+5 -5
View File
@@ -3,10 +3,10 @@ package cron_service
import (
"fmt"
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
"github.com/unknwon/com"
"message-nest/models"
"message-nest/pkg/constant"
"message-nest/pkg/logging"
"message-nest/service/send_message_service"
)
@@ -47,7 +47,7 @@ func (cs *CronService) InitLogsCronRun() {
// 注册任务
setting, err := models.GetSettingByKey(constant.LogsCleanSectionName, constant.LogsCleanCronKeyName)
if err != nil {
logging.Logger.Error(fmt.Sprintf("获取日志的cron失败,原因:%s", err))
logrus.Error(fmt.Sprintf("获取日志的cron失败,原因:%s", err))
}
ClearLogsTaskId = AddTask(ScheduledTask{
Schedule: setting.Value,
@@ -57,7 +57,7 @@ func (cs *CronService) InitLogsCronRun() {
// 添加任务
err = models.AddSendTaskWithID("日志定时清除", constant.CleanLogsTaskId, "admin")
if err != nil {
logging.Logger.Error(fmt.Sprintf("添加日志定时清除任务失败,原因:%s", err))
logrus.Error(fmt.Sprintf("添加日志定时清除任务失败,原因:%s", err))
}
}
@@ -68,8 +68,8 @@ func (cs *CronService) UpdateLogsCronRun(cron string) {
Schedule: cron,
Job: ClearLogs,
})
logging.Logger.Error(fmt.Sprintf("更新日志的cron成功,%s", cron))
logging.Logger.Error(fmt.Sprintf("所有的定时任务: %s", TaskList))
logrus.Error(fmt.Sprintf("更新日志的cron成功,%s", cron))
logrus.Error(fmt.Sprintf("所有的定时任务: %s", TaskList))
}
+4 -3
View File
@@ -3,7 +3,8 @@ package cron_service
import (
"fmt"
"github.com/robfig/cron/v3"
"message-nest/pkg/logging"
"github.com/sirupsen/logrus"
"sync"
)
@@ -33,10 +34,10 @@ func AddTask(task ScheduledTask) cron.EntryID {
taskId, err := CronInstance.AddFunc(task.Schedule, task.Job)
if err != nil {
// 处理错误
logging.Logger.Error(fmt.Sprintf("添加定时任务失败,原因:%s", err))
logrus.Error(fmt.Sprintf("添加定时任务失败,原因:%s", err))
} else {
TaskList[taskId] = &task
logging.Logger.Error(fmt.Sprintf("添加定时任务成功,entryID: %d, cron: %s", taskId, task.Schedule))
logrus.Error(fmt.Sprintf("添加定时任务成功,entryID: %d, cron: %s", taskId, task.Schedule))
}
return taskId
}
+3 -3
View File
@@ -1,9 +1,9 @@
package env_service
import (
"github.com/sirupsen/logrus"
"message-nest/models"
"message-nest/pkg/constant"
"message-nest/pkg/logging"
)
type EnvService struct {
@@ -18,9 +18,9 @@ func (es *EnvService) CommonAdd(section string, key string, value string) {
Value: value,
})
if err != nil {
logging.Logger.Error("初始化%s:%s失败", section, key)
logrus.Error("初始化%s:%s失败", section, key)
} else {
logging.Logger.Infof("初始化%s:%s成功", section, key)
logrus.Infof("初始化%s:%s成功", section, key)
}
}
}
+4 -3
View File
@@ -1,8 +1,9 @@
package send_message_service
import (
"github.com/sirupsen/logrus"
"message-nest/pkg/constant"
"message-nest/pkg/logging"
"sync"
)
@@ -13,7 +14,7 @@ func DoSendTask(task SendMessageService, wg *sync.WaitGroup) {
defer wg.Done()
defer func() {
if r := recover(); r != nil {
logging.Logger.Error("DoSendTask: Recovered from panic:", r)
logrus.Error("DoSendTask: Recovered from panic:", r)
}
}()
@@ -31,7 +32,7 @@ func MessageConsumer(wg *sync.WaitGroup) {
for {
task, ok := <-Buffer
if !ok {
logging.Logger.Error("MessageConsumer: Channel closed. Exiting.")
logrus.Error("MessageConsumer: Channel closed. Exiting.")
return
}
+5 -5
View File
@@ -2,8 +2,8 @@ package send_message_service
import (
"fmt"
"github.com/sirupsen/logrus"
"message-nest/models"
"message-nest/pkg/logging"
"message-nest/service/send_task_service"
"message-nest/service/send_way_service"
"strings"
@@ -38,7 +38,7 @@ func (sm *SendMessageService) LogsAndStatusMark(errStr string, status int) {
if status == SendFail {
sm.Status = SendFail
}
logging.Logger.Error(fmt.Sprintf("%s, 状态:%d", errStr, status))
logrus.Error(fmt.Sprintf("%s, 状态:%d", errStr, status))
}
// Send 发送一个消息任务的所有实例
@@ -158,7 +158,7 @@ func (sm *SendMessageService) RecordSendLog() {
}
err := log.Add()
if err != nil {
logging.Logger.Error(fmt.Sprintf("添加日志失败!原因是:%s", err))
logrus.Error(fmt.Sprintf("添加日志失败!原因是:%s", err))
}
}
@@ -182,10 +182,10 @@ func (sm *SendMessageService) GetSendMsg(ins models.SendTasksIns) (string, strin
if !ok || len(content) == 0 {
content, ok := data["text"]
if !ok {
logging.Logger.Error("text节点数据为空!")
logrus.Error("text节点数据为空!")
return "text", ""
} else {
logging.Logger.Error(fmt.Sprintf("没有找到%s对应的消息,使用text消息替代!", ins.ContentType))
logrus.Error(fmt.Sprintf("没有找到%s对应的消息,使用text消息替代!", ins.ContentType))
return "text", content
}
} else {