Skip to content

Commit

Permalink
feat: 输出日志到文件
Browse files Browse the repository at this point in the history
  • Loading branch information
yearnfar committed Jun 29, 2020
1 parent a6b045c commit bae5f66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/gexrender/gexrender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gexrender
import (
"errors"
"io/ioutil"
"os"
"path/filepath"

"github.com/go-playground/locales/zh"
Expand Down Expand Up @@ -34,6 +35,16 @@ func Render(setting *Setting) (err error) {
log.SetLevel(log.DebugLevel)
}

if setting.LogFile != "" {
logFile, err := os.OpenFile(setting.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
if err != nil {
log.Error(err)
return err
}

log.SetOutput(logFile)
}

if setting.WorkPath == "" {
setting.WorkPath, err = ioutil.TempDir("", "gexrender")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/gexrender/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Setting struct {
SkipCleanup bool // 不清理缓存目录
ForceCommandLinePatch bool // 补丁
Debug bool // 调试模式
LogFile string // 日志输出文件
MultiFrames bool
Reuse bool
StopOnError bool
Expand Down
7 changes: 7 additions & 0 deletions pkg/gexrender/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ func WithDebug() Option {
}
}

// WithLogFile 日志输出到文件
func WithLogFile(file string) Option {
return func(s *gexrender.Setting) {
s.LogFile = file
}
}

// WithConfigFile 提供一个包含作业的json文件的相对或绝对路径代替从参数中使用json。
func WithConfigFile(filename string) Option {
return func(s *gexrender.Setting) {
Expand Down

0 comments on commit bae5f66

Please sign in to comment.