日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python日志文件保存在哪里,Python日志记录-检查日志文件的位置?

發(fā)布時間:2025/3/19 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python日志文件保存在哪里,Python日志记录-检查日志文件的位置? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

What is the methodology for knowing where Python log statements are stored?

i.e. if i do:

import logging

log = logging.getLogger(__name__)

log.info('Test')

Where could I find the logfile? Also, when I call:

logging.getLogger(__name__)

Is that somehow related to how the logger will behave/save?

解決方案

The logging module uses handlers attached to loggers to decide how, where, or even if messages ultimately get stored or displayed. You can configure logging by default to write to a file as well. You should really read the docs, but if you call logging.basicConfig(filename=log_file_name) where log_file_name is the name of the file you want messages written to (note that you have to do this before anything else in logging is called at all), then all messages logged to all loggers (unless some further reconfiguration happens later) will be written there. Be aware of what level the logger is set to though; if memory serves, info is below the default log level, so you'd have to include level=logging.INFO in the arguments to basicConfig as well for your message to end up in the file.

As to the other part of your question, logging.getLogger(some_string) returns a Logger object, inserted in to the correct position in the hierarchy from the root logger, with the name being the value of some_string. Called with no arguments, it returns the root logger. __name__ returns the name of the current module, so logging.getLogger(__name__) returns a Logger object with the name set to the name of the current module. This is a common pattern used with logging, as it causes the logger structure to mirror your code's module structure, which often makes logging messages much more useful when debugging.

總結(jié)

以上是生活随笔為你收集整理的python日志文件保存在哪里,Python日志记录-检查日志文件的位置?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。