{"id":7923,"date":"2016-08-23T18:20:39","date_gmt":"2016-08-23T10:20:39","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7923"},"modified":"2016-08-23T18:26:33","modified_gmt":"2016-08-23T10:26:33","slug":"python-debug%e4%bd%bf%e7%94%a8logging","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7923","title":{"rendered":"python debug\u4f7f\u7528logging"},"content":{"rendered":"<p>\u4f7f\u7528 logging \u6709\u5f88\u591a\u597d\u5904:<\/p>\n<p>    \u53ef\u4ee5\u65b9\u4fbf\u6dfb\u52a0 timestamp<br \/>\n    \u53ef\u4ee5\u4e3a\u65e5\u5fd7\u5b9a\u7ea7<br \/>\n    \u4e0d\u4f1a\u548c\u4e1a\u52a1\u7684 print \u6df7\u6dc6<br \/>\n    \u5982\u679c\u4f60\u5fd8\u4e86\u53bb\u6389 logging \uff0c\u6700\u591a\u4e5f\u53ea\u662f\u6709\u4e00\u4e2a log \u6587\u4ef6<\/p>\n<p>\u5982\u679c\u8981\u6253\u5370\u51fa\u6765<\/p>\n<pre>\r\nimport logging\r\nlogging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')\r\nlogging.debug('This is a log message.')\r\n<\/pre>\n<p>\u5982\u679c\u8981\u653e\u5230\u6587\u4ef6\u91cc<\/p>\n<pre>\r\nimport logging\r\nlogging.basicConfig(filename='log_filename.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')\r\nlogging.debug('This is a log message.')\r\n<\/pre>\n<p>\u62a5\u8b66\u7ea7\u522b<\/p>\n<pre>\r\nlogger.critical('This is a critical message.')\r\nlogger.error('This is an error message.')\r\nlogger.warning('This is a warning message.')\r\nlogger.info('This is an informative message.')\r\nlogger.debug('This is a low-level debug message.')\r\n<\/pre>\n<p>\u0010\u0010\u0010http:\/\/inventwithpython.com\/blog\/2012\/04\/06\/stop-using-print-for-debugging-a-5-minute-quickstart-guide-to-pythons-logging-module\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 logging \u6709\u5f88\u591a\u597d\u5904: \u53ef\u4ee5\u65b9\u4fbf\u6dfb\u52a0 timestamp \u53ef\u4ee5\u4e3a\u65e5\u5fd7\u5b9a\u7ea7 \u4e0d\u4f1a\u548c\u4e1a\u52a1\u7684 print \u6df7\u6dc6 \u5982\u679c\u4f60\u5fd8\u4e86\u53bb\u6389 logging \uff0c\u6700\u591a\u4e5f\u53ea\u662f\u6709\u4e00\u4e2a log \u6587\u4ef6 \u5982\u679c\u8981\u6253\u5370\u51fa\u6765 import logging logging.basicConfig(level=logging.DEBUG, format=&#8217;%(asctime)s &#8211; %(levelname)s &#8211; %(message)s&#8217;) logging.debug(&#8216;This is a log message.&#8217;) \u5982\u679c\u8981\u653e\u5230\u6587\u4ef6\u91cc import logging logging.basicConfig(filename=&#8217;log_filename.txt&#8217;, level=logging.DEBUG, format=&#8217;%(asctime)s &#8211; %(levelname)s &#8211; %(message)s&#8217;) logging.debug(&#8216;This is a log message.&#8217;) \u62a5\u8b66\u7ea7\u522b logger.critical(&#8216;This is a critical message.&#8217;) logger.error(&#8216;This is an error message.&#8217;) logger.warning(&#8216;This [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-7923","post","type-post","status-publish","format-standard","hentry","category-life"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7923"}],"version-history":[{"count":4,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7923\/revisions"}],"predecessor-version":[{"id":7927,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7923\/revisions\/7927"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}