Skip to content

Commit 4d87089

Browse files
authored
Merge pull request #5 from intervention-engine/file-logging
pointed logger to file for persistence through docker volumes
2 parents 029c69a + 75985a3 commit 4d87089

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"strings"
9+
"log"
910

1011
"github.com/robfig/cron"
1112

@@ -25,8 +26,24 @@ func main() {
2526
copyDirFlag := flag.String("copy-dir", "", "Path to a folder where HIE records should be copied locally (env: COPY_DIR, default: none)")
2627
cronFlag := flag.String("cron", "", "Cron expression indicating when the integrator tool should run to refresh data (env: INTEGRATOR_CRON, example: \"0 0 20 * * *\"). If cron is not supplied, \"now\" must be set.")
2728
nowFlag := flag.Bool("now", false, "Flag to indicate if the integrator should run immediately (env: INTEGRATOR_NOW, default: false). If used without cron, integrator will run once and then exit. If now is not set, \"cron\" must be supplied.")
29+
logFileFlag := flag.String("logdir", "", "Path to a directory for integrator logs to be written to.")
2830
flag.Parse()
2931

32+
lfpath := getConfigValue(logFileFlag, "INTEGRATOR_LOG_DIR", "")
33+
if lfpath != "" {
34+
err := os.Mkdir(lfpath, 0755)
35+
if err != nil && !os.IsExist(err){
36+
fmt.Println("Error creating log directory:" + err.Error())
37+
}
38+
lf, err := os.OpenFile(lfpath + "/integrator.log", os.O_RDWR|os.O_APPEND, 0755)
39+
if os.IsNotExist(err) {
40+
lf, err = os.Create(lfpath + "/integrator.log")
41+
}
42+
if err != nil {
43+
fmt.Println("Unable to create ie log file:" + err.Error())
44+
} else {log.SetOutput(lf)}
45+
}
46+
3047
hie := getRequiredConfigValue(hieFlag, "HIE_URL", "HIE URL")
3148
user := getConfigValue(userFlag, "HIE_USER", "")
3249
password := getConfigValue(passwordFlag, "HIE_PASSWORD", "")

0 commit comments

Comments
 (0)