diff --git a/.gitignore b/.gitignore index df947f4..3a8781b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ # Go workspace file go.work - # release binary bin/ + +# log files +*.log diff --git a/main/main.go b/main/main.go index d367d11..e4f9308 100644 --- a/main/main.go +++ b/main/main.go @@ -1,6 +1,9 @@ package main import ( + "os" + "io" + "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" @@ -9,6 +12,16 @@ import ( func init() { log.SetLevel(log.InfoLevel) + debugEnabled := gin.IsDebugging() + + if (!debugEnabled) { + // Disable Console Color when running in 'release' mode + gin.DisableConsoleColor() + + // Logging to a file. + f, _ := os.Create("books.log") + gin.DefaultWriter = io.MultiWriter(f) + } } func setupRouter() *gin.Engine {