简体   繁体   中英

Disable info logs during testing a buffalo application

I am unable to disable INFO logs during testing.

Is there a way to do so?

Thanks.

Set the buffalo.Options.Logger.Out to ioutil.Discard , you might have to create an instance of a logger to do it:

import (
    "github.com/gobuffalo/logger"
    "ioutil"
    // etc.
)

var noopLogger logger.Logrus
noopLogger.Out = ioutil.Discard
noopLogger.SetOutput(ioutil.Discard) // can't remember which one you need to do
buffalo.Options.Logger = noopLogger

Create a new logger, if the env is set to test , in the actions/app.go file with the desired level.

app = buffalo.New(buffalo.Options{
    Env:         ENV,
    SessionName: "_gb_155_session",
})

if env := envy.Get("GO_ENV", ""); env == "test" {
    app.Logger = logger.NewLogger("ERROR")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM