add rawlog

This commit is contained in:
zhiqiang feng
2020-12-28 16:36:59 +08:00
parent f9c71978fd
commit 68069dec34
2 changed files with 11 additions and 2 deletions
+7 -2
View File
@@ -58,7 +58,6 @@ Read the telegram from `,
Mode = os.Getenv(ModeName)
logger *zap.Logger
// l *zap.SugaredLogger
)
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -119,7 +118,7 @@ func initConfig() {
}
func initLog() {
logFile := "./log/telegram-%Y-%m-%d-%H.log"
logFile := "./logs/telegram-%Y-%m-%d-%H.log"
rotator, err := rotatelogs.New(
logFile,
rotatelogs.WithMaxAge(60*24*time.Hour),
@@ -128,6 +127,12 @@ func initLog() {
panic(err)
}
rawFile := "./logs/raw-%Y-%m-%d-%H.txt"
utils.RawLog, err = rotatelogs.New(
rawFile,
rotatelogs.WithMaxAge(60*24*time.Hour),
rotatelogs.WithRotationTime(time.Hour))
priority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl >= zapcore.DebugLevel
})
+4
View File
@@ -3,6 +3,8 @@ package utils
import (
"regexp"
"strings"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
)
const (
@@ -11,6 +13,7 @@ const (
)
var buffer []byte
var RawLog *rotatelogs.RotateLogs
func Append(data []byte) {
buffer = append(buffer, data...)
@@ -28,6 +31,7 @@ func check() {
if len(telegram) > 0 {
// Log.Info("telegram ", zap.String("text", telegram))
RawLog.Write([]byte(telegram))
buffer = nil
InsertTelegram(telegram)
}