Search code examples
gomartini

Set Martini Log Path


How do I set the martini log path to some random file. It is now displaying in console.

m := martini.Classic()

Thanks for the help


Solution

  • Attach a new logger to Martini:

    f, err := os.OpenFile("logfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
    if err != nil {
        t.Fatalf("error opening file: %v", err)
    }
    defer f.Close()
    
    m.Map(log.New(f, "[martini]", log.LstdFlags))