From daedfbde7dacfd5fdabc89d33edbad2778d3a2c7 Mon Sep 17 00:00:00 2001 From: zyj <18107291228@163.com> Date: Mon, 14 Jul 2025 19:01:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file/index.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 file/index.go diff --git a/file/index.go b/file/index.go new file mode 100644 index 0000000..445e34e --- /dev/null +++ b/file/index.go @@ -0,0 +1,20 @@ +package file + +import ( + "os" +) + +// 判断日志文件是否存在 +func LogFileExists(path string, name string) *os.File { + var filePath string = path + if filePath != "" { + logFile, _ := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + logFile.Close() + return logFile + } else { + filePath = "/log/" + name + ".log" + logFile, _ := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + logFile.Close() + return logFile + } +}