Skip to content

Commit

Permalink
add: 添加输出记录到文件的能力2
Browse files Browse the repository at this point in the history
  • Loading branch information
XinRoom committed Feb 21, 2023
1 parent 9871f5c commit e33a54e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions util/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package util

import (
"io"
"log"
"os"
)

func NewLogger(filename string, std bool) *log.Logger {
var out io.Writer
outFile, _ := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if std {
out = io.MultiWriter(os.Stdout, outFile)
} else {
out = outFile
}
logger := log.New(out, "", 0)
return logger
}

0 comments on commit e33a54e

Please sign in to comment.