From e33a54ee3c29ff2f704924bd5b6e100f7591b65c Mon Sep 17 00:00:00 2001 From: XinRoom <32238570+XinRoom@users.noreply.github.com> Date: Tue, 21 Feb 2023 21:57:59 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=88=B0=E6=96=87=E4=BB=B6=E7=9A=84=E8=83=BD?= =?UTF-8?q?=E5=8A=9B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/log.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 util/log.go diff --git a/util/log.go b/util/log.go new file mode 100644 index 0000000..935a10c --- /dev/null +++ b/util/log.go @@ -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 +}