From 3e1b91df27f781e41978685c291fe6621f65c514 Mon Sep 17 00:00:00 2001 From: "kayos@tcp.direct" Date: Sun, 7 Nov 2021 19:48:07 -0800 Subject: [PATCH] Refine: logging and configuration --- config/config.go | 2 ++ config/logger.go | 14 +++++++++----- ssh/server.go | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 ssh/server.go diff --git a/config/config.go b/config/config.go index 88704ad..e0c829d 100644 --- a/config/config.go +++ b/config/config.go @@ -140,6 +140,8 @@ func setConfigFileLocations() { configLocations = append(configLocations, "/etc/"+Title+"/") configLocations = append(configLocations, "../") configLocations = append(configLocations, "../../") + configLocations = append(configLocations, "./") + } } diff --git a/config/logger.go b/config/logger.go index 07d1645..0d1446b 100644 --- a/config/logger.go +++ b/config/logger.go @@ -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()) diff --git a/ssh/server.go b/ssh/server.go new file mode 100644 index 0000000..8104872 --- /dev/null +++ b/ssh/server.go @@ -0,0 +1 @@ +package ssh