Gin: How to log everything into a file?

Created on 16 Feb 2017  路  2Comments  路  Source: gin-gonic/gin

logFile, err := os.Create("production.log")
if err != nil {
  panic(err)
}
gin.DefaultWriter = io.MultiWriter(logFile, os.Stdout)
r := gin.Default()

^ I was expecting everything to be logged into a file & stdout. Everything is being logged into stdout but not everything is being logged into the file. Only http request logs are being logged:

[GIN] 2017/02/15 - 21:55:33 | 200 |  4.382883167s | 112.198.83.128 |   POST    /api/events

Logs generated by log.Println("test") are not being logged in the file.

question

Most helpful comment

log.SetOutput(gin.DefaultWriter) // You may need this
log.Println("test")

All 2 comments

log.SetOutput(gin.DefaultWriter) // You may need this
log.Println("test")

@basco-johnkevin in your example, you are changing the logger of gin, not of log. Check @lawlite answer.

Was this page helpful?
0 / 5 - 0 ratings