英文:
Programmatically turn off logging revel framework
问题
你好!以下是翻译好的内容:
如何以编程方式关闭如下所示的日志记录。我需要这样做以便能够在运行测试套件时不会填充测试日志中的警告和信息日志。
revel.INFO.printf("")
谢谢你的帮助。
英文:
How can I programatically turn of logs like the one below. I need this to be able to run my testsuites with out filling the test logs with warnings and info logs.
revel.INFO.printf("")
Thanks for your help.
答案1
得分: 2
从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函数创建一个新的Logger。out变量设置日志数据将被写入的目标。prefix出现在每个生成的日志行的开头。flag参数定义了日志的属性。
从ioutil
包中,你有:
var Discard io.Writer = devNull(0)
Discard是一个io.Writer,所有的写入调用都成功而不做任何操作。
因此,要关闭revel.INFO
日志,请尝试:
revel.INFO = log.New(ioutil.Discard, "INFO ", log.Ldate|log.Ltime|log.Lshortfile)
英文:
From package revel
you have:
> 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)
> )
From package log
you have:
> 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.
From package ioutil
you have:
> var Discard io.Writer = devNull(0)
>
> Discard is an io.Writer on which all Write calls succeed without doing
> anything.
Therefore, to turn off the revel.INFO
log try:
revel.INFO = log.New(ioutil.Discard, "INFO ", log.Ldate|log.Ltime|log.Lshortfile)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论