diff --git a/g/os/glog/glog.go b/g/os/glog/glog.go index 6f1f6f2d1..c042c4d5b 100644 --- a/g/os/glog/glog.go +++ b/g/os/glog/glog.go @@ -20,6 +20,7 @@ type Logger struct { path *gtype.String // 日志写入的目录路径 debug *gtype.Bool // 是否允许输出DEBUG信息 btSkip *gtype.Int // 错误产生时的backtrace回调信息skip条数 + stdprint *gtype.Bool // 控制台打印开关 @author zseeker } // 默认的日志对象 @@ -32,6 +33,7 @@ func New() *Logger { path : gtype.NewString(), debug : gtype.NewBool(true), btSkip : gtype.NewInt(3), + stdprint : gtype.NewBool(false), } } diff --git a/g/os/glog/glog_logger.go b/g/os/glog/glog_logger.go index 61ce2c34e..b00f56a14 100644 --- a/g/os/glog/glog_logger.go +++ b/g/os/glog/glog_logger.go @@ -27,16 +27,13 @@ const ( // 默认的日志换行符 var ln = "\n" -// 控制台打印开关 -var stdprint = false - // 初始化日志换行符 // @author zseeker // @date 2018-05-23 func init() { if runtime.GOOS == "windows" { ln = "\r\n" - } + } } // 设置BacktraceSkip @@ -100,8 +97,9 @@ func (l *Logger) SetPath(path string) error { // 设置写日志时开启or关闭控制台打印,默认是关闭的 // @author zseeker +// @date 2018-05-24 func (l *Logger) SetStdPrint(open bool) { - stdprint = open + l.stdprint.Set(open) } // 这里的写锁保证统一时刻只会写入一行日志,防止串日志的情况 @@ -111,8 +109,8 @@ func (l *Logger) print(defaultIO io.Writer, s string) { if v := l.getFileByPool(); v != nil { w = v.File() // 同时输出到文件和终端 @author zseeker - if stdprint { - w = io.MultiWriter(w, os.Stdout) + if l.stdprint.Val() { + w = io.MultiWriter(w, defaultIO) } defer v.Close() } else {