From e8e3e0e71dd0fccf109683524f9bef351ab5f502 Mon Sep 17 00:00:00 2001 From: wangyj Date: Wed, 17 Jan 2018 11:13:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20lumberjack=20=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=E5=88=87=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/temp.sql | 0 fsm.go | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .vscode/temp.sql diff --git a/.vscode/temp.sql b/.vscode/temp.sql new file mode 100644 index 0000000..e69de29 diff --git a/fsm.go b/fsm.go index f473767..fd07a9b 100644 --- a/fsm.go +++ b/fsm.go @@ -31,6 +31,7 @@ import ( "github.com/kennygrant/sanitize" "github.com/lunny/dingtalk_webhook" + "github.com/natefinch/lumberjack" "github.com/qiniu/log" "github.com/soopsio/gosuv/pushover" "github.com/soopsio/kexec" @@ -212,7 +213,7 @@ type Process struct { Stdout *QuickLossBroadcastWriter `json:"-"` Stderr *QuickLossBroadcastWriter `json:"-"` Output *QuickLossBroadcastWriter `json:"-"` - OutputFile *os.File `json:"-"` + OutputFile io.WriteCloser `json:"-"` stopC chan syscall.Signal retryLeft int Status string `json:"status"` @@ -230,7 +231,17 @@ func (p *Process) buildCommand() *kexec.KCommand { } var fout io.Writer var err error - p.OutputFile, err = os.OpenFile(filepath.Join(logDir, "output.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) + // p.OutputFile, err = os.OpenFile(filepath.Join(logDir, "output.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) + // p.OutputFile = NewRotate(filepath.Join(logDir, "output.log")) + p.OutputFile = &lumberjack.Logger{ + Filename: filepath.Join(logDir, "output.log"), + MaxSize: 1024, + MaxAge: 14, + MaxBackups: 14, + Compress: false, + LocalTime: true, + } + if err != nil { log.Warn("create stdout log failed:", err) fout = ioutil.Discard