gpt4 book ai didi

logging - 以编程方式关闭日志记录 revel 框架

转载 作者:IT王子 更新时间:2023-10-29 02:05:22 25 4
gpt4 key购买 nike

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

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)

关于logging - 以编程方式关闭日志记录 revel 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29986674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com