以编程方式关闭日志记录狂欢框架

Programmatically turn off logging revel framework

如何以编程方式关闭如下所示的日志。我需要它能够 运行 我的测试套件,而不用警告和信息日志填充测试日志。

revel.INFO.printf("")

感谢您的帮助。

来自包 revel 你有:

var (
    // Loggers
    TRACE = log.New(ioutil.Discard, "TRACE ", log.Ldate|log.Ltime|log.Lshortfile)
    INFO  = log.New(ioutil.Discard, "INFO  ", log.Ldate|log.Ltime|log.Lshortfile)
    WARN  = log.New(ioutil.Discard, "WARN  ", log.Ldate|log.Ltime|log.Lshortfile)
    ERROR = log.New(&error_log, "ERROR ", log.Ldate|log.Ltime|log.Lshortfile)
)

来自包 log 你有:

func New

func New(out io.Writer, prefix string, flag int) *Logger

New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line. The flag argument defines the logging properties.

从包裹 ioutil 你有:

var Discard io.Writer = devNull(0)

Discard is an io.Writer on which all Write calls succeed without doing anything.

因此,要关闭 revel.INFO 日志,请尝试:

revel.INFO = log.New(ioutil.Discard, "INFO  ", log.Ldate|log.Ltime|log.Lshortfile)