does gin-gonic has similar API as martini can easily re-direct log to a file
e.g
m.Map(log.New(f, "[martini]", log.LstdFlags))
How about this? https://github.com/gin-gonic/gin/commit/6c788a43004f9763178738a2c2f7a6d276fd60d5
gin.DefaultLogFile = os.Stdout
router := gin.Default()
the idea: the logger middleware takes the gin.DefaultLogFile as default file.
but you can be even more explicit:
yourfile, _ := os.Create("server.log")
router := gin.New()
router.Use(gin.LoggerWithFile(yourfile))
I would have a look at http://golang.org/pkg/io/#MultiWriter to enable both logging to the console and file, works really well.
you could still use MultiWriter()
myfile, _ := os.Create("server.log")
gin.DefaultLogFile = io.MultiWriter(myfile, os.Stdout)
router := gin.Default()
// ...
maybe DefaultLogFile is not the best name. how about DefaultWriter? any idea?
+1 for DefaultWriter
ok, it's done!
Most helpful comment
you could still use MultiWriter()
maybe
DefaultLogFileis not the best name. how aboutDefaultWriter? any idea?