您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python不创建日志文件

5b51 2022/1/14 8:23:11 python 字数 2042 阅读 568 来源 www.jb51.cc/python

我正在尝试实现一些日志记录来记录消息.我得到一些奇怪的行为,所以我试图找到一个最小的例子,我发现了 here.当我只是将简单的例子描述到我的解释器文件没有创建,你可以看到这里: In [1]: import logging ...: logging.basicConfig(filename='example.log',level=logging.DEBUG) ...: logging.

概述

In [1]: import logging
   ...: logging.basicConfig(filename='example.log',level=logging.DEBUG)
   ...: logging.debug('This message should go to the log file')
   ...: logging.info('So should this')
   ...: logging.warning('And this,too')
WARNING:root:And this,too

In [2]: ls example.log

File not found

有人可以帮助我了解我做错了什么吗?谢谢…

编辑:将第二次输入后的输出改为英文,并删除不必要的部分.唯一重要的是Python不会创建文件example.log.

This function does nothing if the root logger already has handlers
configured for it.

你所得到的只是Python是这样的:

C:\temp>python
ActivePython 2.6.1.1 (ActiveState Software Inc.) based on
Python 2.6.1 (r261:67515,Dec  5 2008,13:58:38) [MSC v.1500 32 bit (Intel)] on
win32
Type "help","copyright","credits" or "license" for more information.
>>> import logging
>>> logging.basicConfig(filename='example.log',level=logging.DEBUG)
>>> logging.debug('This message should go to the log file')
>>> logging.info('And so should this')
>>> logging.warning('And this,too')
>>> ^Z

C:\temp>type example.log
DEBUG:root:This message should go to the log file
INFO:root:And so should this
WARNING:root:And this,too

总结

以上是编程之家为你收集整理的Python不创建日志文件全部内容,希望文章能够帮你解决Python不创建日志文件所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶