此日志记录到哪里? [英] Where is this logging to?

查看:59
本文介绍了此日志记录到哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个python代码:

I have this python code:

import logging
LOGGER = logging.getLogger(__name__)
LOGGER.info('test')

它没有被写入控制台,所以该记录在哪里?

It does not get written to the console, so where does this get logged?

推荐答案

由于您未配置任何日志记录处理程序,因此该记录不会在任何地方记录.如果未配置处理程序,则日志事件将消失.如果未配置任何处理程序,则如果看到WARNING或更高级别的事件,但您的事件只是INFO级别,则根记录程序会自动添加一个处理程序.

This does not get logged anywhere, because you did not configure any logging handlers. Without a handler configured, the log event goes nowhere. When there are no handlers configured, the root logger gets a handler automatically added if an event at WARNING or above is seen, but your event was just at INFO level.

如果您之前放置过这样的行,那么您将看到它记录到终端:

If you put a line like this before, then you will see it logged to terminal:

logging.basicConfig(level=logging.INFO)

如果没有另外指定,基本配置将在sys.stderr上添加StreamHandler文字.

Basic config will add a StreamHandler writing to sys.stderr if you don't specify otherwise.

这篇关于此日志记录到哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆