This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/elektronLogging/createLogDir.go
2019-11-20 13:33:46 -05:00

38 lines
937 B
Go

package elektronLogging
import (
logrus "github.com/sirupsen/logrus"
"os"
"strconv"
"time"
)
var logDir string
func GetLogDir(startTime time.Time, prefix string) {
if logDir == "" {
logDir = createLogDir(prefix, startTime)
}
}
func createLogDir(prefix string, startTime time.Time) string {
// Creating directory to store all logs for this run
logDirName := "./" + prefix + strconv.Itoa(startTime.Year())
logDirName += "-"
logDirName += startTime.Month().String()
logDirName += "-"
logDirName += strconv.Itoa(startTime.Day())
logDirName += "_"
logDirName += strconv.Itoa(startTime.Hour())
logDirName += "-"
logDirName += strconv.Itoa(startTime.Minute())
logDirName += "-"
logDirName += strconv.Itoa(startTime.Second())
if _, err := os.Stat(logDirName); os.IsNotExist(err) {
os.Mkdir(logDirName, 0755)
} else {
logrus.Println("Unable to create log directory: ", err)
logDirName = ""
}
return logDirName
}