{"id":50589,"date":"2024-12-03T16:36:07","date_gmt":"2024-12-03T08:36:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50589\/"},"modified":"2024-12-03T16:36:07","modified_gmt":"2024-12-03T08:36:07","slug":"python-%e7%b1%bb%e5%9e%8b%e7%ba%a6%e6%9d%9f%ef%bc%9apyi-%e6%96%87%e4%bb%b6%e5%a6%82%e4%bd%95%e5%a2%9e%e5%bc%ba%e4%bb%a3%e7%a0%81%e6%a3%80%e6%9f%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50589\/","title":{"rendered":"Python \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aPython \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323344646741538050762.jpg\" class=\"aligncenter\" title=\"Python \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f\u63d2\u56fe\" alt=\"Python \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>python \u7c7b\u7ea6\u675f\uff1a\u6df1\u5165\u4e86\u89e3\u7c7b\u578b\u68c0\u67e5<\/strong><\/p>\n<p>\u5728 python \u7684\u7c7b\u578b\u68c0\u67e5\u8fc7\u7a0b\u4e2d\uff0cloguru \u5e93\u4e2d\u7684\u4e00\u4e2a\u7279\u6b8a\u7c7b\u5199\u6cd5\u5f15\u8d77\u4e86\u6ce8\u610f\uff1a\u4f7f\u7528\u7ea2\u6846\u6807\u8bc6\u7684\u4ee3\u7801\u7247\u6bb5\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u8fd9\u79cd\u5199\u6cd5\u7684\u4f5c\u7528\uff0c\u63ed\u793a\u5176\u5728\u4ee3\u7801\u7ea6\u675f\u548c\u7c7b\u578b\u68c0\u67e5\u4e2d\u7684\u91cd\u8981\u6027\u3002<\/p>\n<p><strong>\u4ec0\u4e48\u662f pyi \u6587\u4ef6\uff1f<\/strong><\/p>\n<p>\u7ea2\u6846\u4e2d\u7684\u4ee3\u7801\u5b9e\u9645\u4e0a\u4f4d\u4e8e\u4e00\u4e2a pyi \u6587\u4ef6\u4e2d\uff0c\u800c\u4e0d\u662f\u6807\u51c6\u7684 py \u6587\u4ef6\u4e2d\u3002pyi \u6587\u4ef6\u7684\u4f5c\u7528\u662f\u5305\u542b\u7c7b\u578b\u4fe1\u606f\uff0c\u4e3a python \u4ee3\u7801\u63d0\u4f9b\u989d\u5916\u7684\u7c7b\u578b\u7ea6\u675f\u3002\u6709\u4e86 pyi \u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u66f4\u4e25\u683c\u5730\u68c0\u67e5\u4ee3\u7801\u4e2d\u7684\u7c7b\u578b\uff0c\u786e\u4fdd\u5b83\u4eec\u6ee1\u8db3\u9884\u671f\u7684\u8981\u6c42\u3002<\/p>\n<p><strong>\u4ee3\u7801\u5199\u6cd5\u7684\u8bf4\u660e<\/strong><\/p>\n<p>\u4ee3\u7801\u884c &#8220;logger: logger&#8221; \u7528\u4e00\u4e2a\u4f17\u6240\u5468\u77e5\u7684\u7c7b\u7ea6\u675f\u3002\u8fd9\u610f\u5473\u7740\u53d8\u91cf logger \u5fc5\u987b\u662f logger \u7c7b\u7684\u5b9e\u4f8b\uff0c\u5426\u5219\u7c7b\u578b\u68c0\u67e5\u5de5\u5177\u5c06\u53d1\u51fa\u9519\u8bef\u3002\u8fd9\u79cd\u7ea6\u675f\u786e\u4fdd\u4e86\u4ee3\u7801\u5728\u4f7f\u7528 logger \u65f6\u53ea\u4f1a\u63a5\u53d7 logger \u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u4ece\u800c\u9632\u6b62\u610f\u5916\u7684\u8d4b\u503c\u6216\u4f7f\u7528\u4e0d\u6b63\u786e\u7684\u7c7b\u578b\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u7c7b\u578b\u7ea6\u675f\uff1f<\/strong><\/p>\n<p>\u7c7b\u578b\u7ea6\u675f\u5bf9\u4e8e\u4fdd\u6301\u4ee3\u7801\u7684\u51c6\u786e\u6027\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5f3a\u5236\u6267\u884c\u9884\u671f\u7684\u7c7b\u578b\u3002\u8fd9\u6709\u52a9\u4e8e<strong>\u9632\u6b62\u610f\u5916\u9519\u8bef<\/strong>\uff0c<strong>\u51cf\u5c11\u4ee3\u7801\u8c03\u8bd5\u65f6\u95f4<\/strong>\uff0c\u5e76<strong>\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027<\/strong>\u3002\u6b64\u5916\uff0c\u7c7b\u578b\u7ea6\u675f\u8fd8\u53ef\u4ee5\u5728\u5355\u5143\u6d4b\u8bd5\u548c\u6301\u7eed\u96c6\u6210\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u989d\u5916\u7684\u4fdd\u8bc1\u3002<\/p>\n<p><strong>\u4f7f\u7528 logger \u53d8\u91cf\u7684\u793a\u4f8b<\/strong><\/p>\n<p>\u4e86\u89e3\u4e86\u7c7b\u7ea6\u675f\u540e\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 logger \u53d8\u91cf\uff1a<\/p>\n<pre>from loguru import logger\n\nlogger.info(\"Starting application...\")\nlogger.error(\"An error occurred during processing.\")<\/pre>\n<p>\u7531\u4e8e\u4f7f\u7528\u4e86 logger \u7c7b\u7ea6\u675f\uff0c\u6211\u4eec\u53ea\u80fd\u5c06 logger \u5bf9\u8c61\u8d4b\u503c\u7ed9 logger \u53d8\u91cf\u3002\u8fd9\u786e\u4fdd\u4e86\u6211\u4eec\u4e0d\u4f1a\u610f\u5916\u5730\u7ed9\u5b83\u5206\u914d\u4efb\u4f55\u5176\u4ed6\u7c7b\u578b\uff0c\u4ece\u800c\u786e\u4fdd\u4e86\u4ee3\u7801\u7684\u7c7b\u578b\u5b89\u5168\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPython \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f \u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aPython \u7c7b\u578b\u7ea6\u675f\uff1apyi \u6587\u4ef6\u5982\u4f55\u589e\u5f3a\u4ee3\u7801\u68c0\u67e5\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01 python \u7c7b\u7ea6\u675f\uff1a\u6df1\u5165\u4e86\u89e3\u7c7b\u578b\u68c0\u67e5 \u5728 python \u7684\u7c7b\u578b\u68c0\u67e5\u8fc7\u7a0b\u4e2d\uff0cloguru \u5e93\u4e2d\u7684\u4e00\u4e2a\u7279\u6b8a\u7c7b\u5199\u6cd5\u5f15\u8d77\u4e86\u6ce8\u610f\uff1a\u4f7f\u7528\u7ea2\u6846\u6807\u8bc6\u7684\u4ee3\u7801\u7247\u6bb5\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u8fd9\u79cd\u5199\u6cd5\u7684\u4f5c\u7528\uff0c\u63ed\u793a\u5176\u5728\u4ee3\u7801\u7ea6\u675f\u548c\u7c7b\u578b\u68c0\u67e5\u4e2d\u7684\u91cd\u8981\u6027\u3002 \u4ec0\u4e48\u662f pyi \u6587\u4ef6\uff1f \u7ea2\u6846\u4e2d\u7684\u4ee3\u7801\u5b9e\u9645\u4e0a\u4f4d\u4e8e\u4e00\u4e2a pyi \u6587\u4ef6\u4e2d\uff0c\u800c\u4e0d\u662f\u6807\u51c6\u7684 py \u6587\u4ef6\u4e2d\u3002pyi \u6587\u4ef6\u7684\u4f5c\u7528\u662f\u5305\u542b\u7c7b\u578b\u4fe1\u606f\uff0c\u4e3a python \u4ee3\u7801\u63d0\u4f9b\u989d\u5916\u7684\u7c7b\u578b\u7ea6\u675f\u3002\u6709\u4e86 pyi \u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u66f4\u4e25\u683c\u5730\u68c0\u67e5\u4ee3\u7801\u4e2d\u7684\u7c7b\u578b\uff0c\u786e\u4fdd\u5b83\u4eec\u6ee1\u8db3\u9884\u671f\u7684\u8981\u6c42\u3002 \u4ee3\u7801\u5199\u6cd5\u7684\u8bf4\u660e \u4ee3\u7801\u884c &#8220;logger: logger&#8221; \u7528\u4e00\u4e2a\u4f17\u6240\u5468\u77e5\u7684\u7c7b\u7ea6\u675f\u3002\u8fd9\u610f\u5473\u7740\u53d8\u91cf logger \u5fc5\u987b\u662f logger \u7c7b\u7684\u5b9e\u4f8b\uff0c\u5426\u5219\u7c7b\u578b\u68c0\u67e5\u5de5\u5177\u5c06\u53d1\u51fa\u9519\u8bef\u3002\u8fd9\u79cd\u7ea6\u675f\u786e\u4fdd\u4e86\u4ee3\u7801\u5728\u4f7f\u7528 logger \u65f6\u53ea\u4f1a\u63a5\u53d7 logger \u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u4ece\u800c\u9632\u6b62\u610f\u5916\u7684\u8d4b\u503c\u6216\u4f7f\u7528\u4e0d\u6b63\u786e\u7684\u7c7b\u578b\u3002 \u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u7c7b\u578b\u7ea6\u675f\uff1f \u7c7b\u578b\u7ea6\u675f\u5bf9\u4e8e\u4fdd\u6301\u4ee3\u7801\u7684\u51c6\u786e\u6027\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5f3a\u5236\u6267\u884c\u9884\u671f\u7684\u7c7b\u578b\u3002\u8fd9\u6709\u52a9\u4e8e\u9632\u6b62\u610f\u5916\u9519\u8bef\uff0c\u51cf\u5c11\u4ee3\u7801\u8c03\u8bd5\u65f6\u95f4\uff0c\u5e76\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u6b64\u5916\uff0c\u7c7b\u578b\u7ea6\u675f\u8fd8\u53ef\u4ee5\u5728\u5355\u5143\u6d4b\u8bd5\u548c\u6301\u7eed\u96c6\u6210\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u989d\u5916\u7684\u4fdd\u8bc1\u3002 \u4f7f\u7528 logger \u53d8\u91cf\u7684\u793a\u4f8b \u4e86\u89e3\u4e86\u7c7b\u7ea6\u675f\u540e\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 logger \u53d8\u91cf\uff1a from loguru import logger logger.info(&#8220;Starting application&#8230;&#8221;) logger.error(&#8220;An error occurred [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-50589","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=50589"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50589\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}