Skip to content

Commit

Permalink
toggle logging to stdio or file based on release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
GarbhanK committed May 26, 2024
1 parent 4c8b0df commit d40f742
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# Go workspace file
go.work


# release binary
bin/

# log files
*.log
13 changes: 13 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"os"
"io"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"

Expand All @@ -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 {
Expand Down

0 comments on commit d40f742

Please sign in to comment.