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 + } +}