From 674327e0cfcf9282b59471d2018914b092655b38 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sat, 3 Sep 2022 10:51:25 -0400 Subject: [PATCH] Added a multi-writer so that log messages go to both the console and log file --- config/log.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config/log.go b/config/log.go index c660f84..9c5d66d 100644 --- a/config/log.go +++ b/config/log.go @@ -1,6 +1,7 @@ package config import ( + "io" "log" "os" @@ -20,10 +21,12 @@ func InitLogging() *os.File { log.Fatalf("Error opening log file: %v", err) os.Exit(1) } - - // set logging to file handle - log.SetOutput(fileHandle) } + // create a MultiWriter instance so we can write to both console AND file + mw := io.MultiWriter(os.Stdout, fileHandle) + // set our multiwriter object as the output for logging + log.SetOutput(mw) + return fileHandle }