|
@@ -12,21 +12,21 @@ const (
|
|
dateFormat = "20060102"
|
|
dateFormat = "20060102"
|
|
)
|
|
)
|
|
|
|
|
|
-func getWriter() *csv.Writer {
|
|
|
|
|
|
+func getWriter() (*csv.Writer, *os.File) {
|
|
logFile := filepath.Join("log", (time.Now().Format(dateFormat) + ".log"))
|
|
logFile := filepath.Join("log", (time.Now().Format(dateFormat) + ".log"))
|
|
logOutput, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
|
logOutput, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Fatalf("Error creating log file: %v", err)
|
|
|
|
|
|
+ log.Fatalf("Log file error: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
writer := csv.NewWriter(logOutput)
|
|
writer := csv.NewWriter(logOutput)
|
|
- return writer
|
|
|
|
|
|
+ return writer, logOutput
|
|
}
|
|
}
|
|
|
|
|
|
-// WriteLog main function, saves event to the log.
|
|
|
|
-func WriteLog(info SearchInfo) {
|
|
|
|
- writer := getWriter()
|
|
|
|
|
|
+func writeLog(info SearchInfo) {
|
|
|
|
+ writer, file := getWriter()
|
|
|
|
|
|
writer.Write(info.ToArray())
|
|
writer.Write(info.ToArray())
|
|
writer.Flush()
|
|
writer.Flush()
|
|
|
|
+ file.Close()
|
|
}
|
|
}
|