Refine: logging and configuration

This commit is contained in:
kayos@tcp.direct 2021-11-07 19:48:07 -08:00
parent f87b1f17e2
commit 3e1b91df27
3 changed files with 12 additions and 5 deletions

View File

@ -140,6 +140,8 @@ func setConfigFileLocations() {
configLocations = append(configLocations, "/etc/"+Title+"/")
configLocations = append(configLocations, "../")
configLocations = append(configLocations, "../../")
configLocations = append(configLocations, "./")
}
}

View File

@ -20,19 +20,23 @@ var (
// While this does return a logger, it should not be used for additional retrievals of the logger. Use GetLogger()
func StartLogger() zerolog.Logger {
logDir = snek.GetString("logger.directory")
if err := os.MkdirAll(logDir, 0755); err != nil {
if !strings.HasSuffix(logDir, "/") {
logDir = logDir + "/"
}
if err := os.MkdirAll(logDir, os.ModePerm); err != nil {
println("cannot create log directory: " + logDir + "(" + err.Error() + ")")
os.Exit(1)
}
tnow := "HellPot"
logFileName := "HellPot"
if snek.GetBool("logger.use_date_filename") {
tnow = strings.Replace(time.Now().Format(time.RFC822), " ", "_", -1)
tnow = strings.Replace(tnow, ":", "-", -1)
tn := strings.Replace(time.Now().Format(time.RFC822), " ", "_", -1)
tn = strings.Replace(logFileName, ":", "-", -1)
logFileName = logFileName + "_" + tn
}
CurrentLogFile = logDir + tnow + ".log"
CurrentLogFile = logDir + logFileName + ".log"
if logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil {
println("cannot create log file: " + err.Error())

1
ssh/server.go Normal file
View File

@ -0,0 +1 @@
package ssh