{"id":1358,"date":"2019-12-18T22:07:21","date_gmt":"2019-12-18T14:07:21","guid":{"rendered":"http:\/\/vip.fxxkpython.com\/?p=1358"},"modified":"2019-12-18T22:07:21","modified_gmt":"2019-12-18T14:07:21","slug":"python-%e7%88%ac%e9%98%b6%e6%a2%af-%e5%a6%82%e4%bd%95%e5%9c%a8-python-%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%97%a5%e5%bf%97-logging","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=1358","title":{"rendered":"Python \u722c\u9636\u68af | \u5982\u4f55\u5728 Python \u4e2d\u4f7f\u7528\u65e5\u5fd7 \u2014\u2014 logging"},"content":{"rendered":"\n<p>\u6211\u60f3\u4f60\u5728\u5199\u4ee3\u7801\u7684\u65f6\u5019\u901a\u5e38\u4f1a\u4f7f\u7528\u5230 print \u6765\u6253\u5370\u4e00\u4e9b\u4fe1\u606f\uff0c\u4e3b\u8981\u662f\u60f3\u770b\u770b\u4ee3\u7801\u6267\u884c\u7684\u76f8\u5173\u6d41\u7a0b\uff0c\u5b83\u66f4\u591a\u7684\u9002\u7528\u5728\u7a0b\u5e8f\u6267\u884c\u65f6\uff0c\u76f4\u63a5\u5728 console \u4e2d\u770b\u7a0b\u5e8f\u7684\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\u5c0f\u5e05b\u8981\u8ddf\u4f60\u8bf4\u8bf4\u65e5\u5fd7\u8fd9\u4e2a\u73a9\u610f\u4e86\uff0c\u5148\u8ddf\u4f60\u8bf4\u4e0b\uff0c\u4e3a\u5565\u6211\u4eec\u8981\u4f7f\u7528\u65e5\u5fd7\u5462\uff1f\u5728\u6211\u770b\u6765\uff0c\u6709\u8fd9\u4e48\u51e0\u70b9\uff1a<\/p>\n\n\n\n<p>1\u3001 \u5b83\u53ef\u4ee5\u8bb0\u5f55\u4f60\u5199\u7684\u4ee3\u7801\u7684\u60c5\u51b5\uff0c\u6bd4\u5982\u7528\u6237\u5728\u4ec0\u4e48\u65f6\u5019\u505a\u4e86\u4ec0\u4e48\u64cd\u4f5c\uff0c\u5bfc\u81f4\u4e86\u4ec0\u4e48\u6837\u7684\u9519\u8bef\uff0c\u5728\u54ea\u4e00\u884c\u4ee3\u7801\u51fa\u9519\u4e86&#8230;<\/p>\n\n\n\n<p>2\u3001\u53ef\u4ee5\u6e05\u6670\u7684\u4e86\u89e3\u4f60\u7684\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n\n\n\n<p>3\u3001\u53ef\u4ee5\u901a\u8fc7\u65e5\u5fd7\u6765\u5206\u6790\uff0c\u4f60\u7684\u4ee3\u7801\u54ea\u91cc\u53ef\u4ee5\u4f18\u5316\u5f97\u66f4\u597d\u4e00\u70b9\u3002<\/p>\n\n\n\n<p>4\u3001\u65e5\u5fd7\u548c\u76f4\u63a5 print \u7684\u533a\u522b\u5728\u4e8e\uff0c\u65e5\u5fd7\u53ef\u4ee5\u5b58\u50a8\uff0c\u4f60\u53ef\u4ee5\u5c06\u8bb0\u5f55\u4e0b\u6765\u7684\u65e5\u5fd7\u5b58\u50a8\u5230\u6307\u5b9a\u7684\u76ee\u5f55\uff0c\u6839\u636e\u65f6\u95f4\u533a\u5206\u6587\u4ef6\uff0c\u4e0b\u6b21\u5c31\u53ef\u4ee5\u76f4\u63a5\u5230\u6307\u5b9a\u4f4d\u7f6e\u67e5\u770b\u3002<\/p>\n\n\n\n<p>5\u3001\u65e5\u5fd7\u53ef\u4ee5\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u8ba9\u65e5\u5fd7\u4ee5\u4f60\u559c\u6b22\u7684\u683c\u5f0f\u8f93\u51fa\uff0c\u53ef\u4ee5\u6307\u5b9a\u5b83\u7684\u5b58\u50a8\u4f4d\u7f6e\u7b49\u3002<\/p>\n\n\n\n<p>\u5728 Python \u4e2d\u6709\u4e2a\u5185\u7f6e\u7684\u6a21\u5757\uff0c\u5c31\u662f logging \uff0c\u901a\u8fc7\u5b83\u6211\u4eec\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5728\u6211\u4eec\u7684\u989d\u4ee3\u7801\u91cc\u9762\u6dfb\u52a0\u65e5\u5fd7\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0clogging \u7684\u7ea7\u522b\u6709\u8fd9\u4e48\u51e0\u79cd\uff1a<div style=\"text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;\">\u672c\u6587\u9690\u85cf\u5185\u5bb9 <a href=\"https:\/\/vip.fxxkpython.com\/wp-login.php?redirect_to=https%3A%2F%2Fvip.fxxkpython.com%2F%3Fp%3D1358\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u7136\u540e\u5728\u4ee3\u7801\u4e2d\u5f15\u7528\u8fd9\u4e2a\u6587\u4ef6\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" width=\"646\" height=\"460\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2019\/12\/Screenshot-from-2019-12-18-22-03-32.png\" alt=\"\" class=\"wp-image-1375\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2019\/12\/Screenshot-from-2019-12-18-22-03-32.png 646w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2019\/12\/Screenshot-from-2019-12-18-22-03-32-300x214.png 300w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd0\u884c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" width=\"714\" height=\"159\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2019\/12\/Screenshot-from-2019-12-18-22-03-54.png\" alt=\"\" class=\"wp-image-1376\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2019\/12\/Screenshot-from-2019-12-18-22-03-54.png 714w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2019\/12\/Screenshot-from-2019-12-18-22-03-54-300x67.png 300w\" sizes=\"(max-width: 714px) 100vw, 714px\" \/><\/figure><\/div>\n\n\n\n<p>\u914d\u7f6e\u6587\u4ef6\u6a21\u677f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>[loggers]<\/strong> <br>keys=root,simpleExample <br><br><strong>[handlers]<\/strong> <br>keys=consoleHandler <br><br><strong>[formatters]<\/strong> <br>keys=simpleFormatter <br><br><strong>[logger_root]<\/strong> <br>level=DEBUG handlers=consoleHandler<br> <br><strong>[logger_simpleExample]<\/strong> <br>level=DEBUG <br>handlers=consoleHandler <br>qualname=simpleExample propagate=0 <br><br><strong>[handler_consoleHandler]<\/strong> <br>class=StreamHandler <br>level=DEBUG <br>formatter=simpleFormatter <br>args=(sys.stdout,) <br><br><strong>[formatter_simpleFormatter]<\/strong> <br>format=%(asctime)s - %(name)s - %(levelname)s - %(message)s <br>datefmt=<\/pre>\n\n\n\n<p>ok\uff0c\u4ee5\u4e0a\u5c31\u662f logging \u7684\u4f7f\u7528\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u60f3\u4f60\u5728\u5199\u4ee3\u7801\u7684\u65f6\u5019\u901a\u5e38\u4f1a\u4f7f\u7528\u5230 print \u6765\u6253\u5370\u4e00\u4e9b\u4fe1\u606f\uff0c\u4e3b\u8981\u662f\u60f3\u770b\u770b\u4ee3\u7801\u6267\u884c\u7684\u76f8\u5173\u6d41\u7a0b\uff0c\u5b83\u66f4\u591a\u7684\u9002\u7528\u5728\u7a0b\u5e8f\u6267\u884c\u65f6\uff0c\u76f4\u63a5\u5728 console \u4e2d\u770b\u7a0b\u5e8f\u7684\u8fd0\u884c\u60c5\u51b5\u3002 \u4eca\u5929\u5c0f\u5e05b\u8981\u8ddf\u4f60\u8bf4\u8bf4\u65e5\u5fd7\u8fd9\u4e2a\u73a9\u610f\u4e86\uff0c\u5148\u8ddf\u4f60\u8bf4\u4e0b\uff0c\u4e3a\u5565\u6211\u4eec\u8981\u4f7f\u7528\u65e5\u5fd7\u5462\uff1f\u5728\u6211\u770b\u6765\uff0c\u6709\u8fd9&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[140],"tags":[237,125,236,234,233,232,235],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/1358"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1358"}],"version-history":[{"count":1,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/1358\/revisions"}],"predecessor-version":[{"id":1377,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/1358\/revisions\/1377"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}