Refine: logging and configuration
This commit is contained in:
parent
f87b1f17e2
commit
3e1b91df27
|
@ -140,6 +140,8 @@ func setConfigFileLocations() {
|
||||||
configLocations = append(configLocations, "/etc/"+Title+"/")
|
configLocations = append(configLocations, "/etc/"+Title+"/")
|
||||||
configLocations = append(configLocations, "../")
|
configLocations = append(configLocations, "../")
|
||||||
configLocations = append(configLocations, "../../")
|
configLocations = append(configLocations, "../../")
|
||||||
|
configLocations = append(configLocations, "./")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,19 +20,23 @@ var (
|
||||||
// While this does return a logger, it should not be used for additional retrievals of the logger. Use GetLogger()
|
// While this does return a logger, it should not be used for additional retrievals of the logger. Use GetLogger()
|
||||||
func StartLogger() zerolog.Logger {
|
func StartLogger() zerolog.Logger {
|
||||||
logDir = snek.GetString("logger.directory")
|
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() + ")")
|
println("cannot create log directory: " + logDir + "(" + err.Error() + ")")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
tnow := "HellPot"
|
logFileName := "HellPot"
|
||||||
|
|
||||||
if snek.GetBool("logger.use_date_filename") {
|
if snek.GetBool("logger.use_date_filename") {
|
||||||
tnow = strings.Replace(time.Now().Format(time.RFC822), " ", "_", -1)
|
tn := strings.Replace(time.Now().Format(time.RFC822), " ", "_", -1)
|
||||||
tnow = strings.Replace(tnow, ":", "-", -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 {
|
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())
|
println("cannot create log file: " + err.Error())
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
package ssh
|
Loading…
Reference in New Issue