{"id":718,"date":"2017-03-18T23:41:18","date_gmt":"2017-03-18T14:41:18","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=718"},"modified":"2020-05-03T20:49:33","modified_gmt":"2020-05-03T11:49:33","slug":"logginglogger-%e3%83%ad%e3%82%b0%e5%87%ba%e5%8a%9b-%e3%81%9d%e3%81%ae3","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/718","title":{"rendered":"logging \u30ed\u30b0\u306e\u968e\u5c64"},"content":{"rendered":"<h2>\u30ed\u30ac\u30fc\u306e\u968e\u5c64<\/h2>\n<p>\u524d\u56de\u306e\u7d9a\u304d\u3067\u30ed\u30ac\u30fc\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u30ed\u30ac\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306f\u305d\u308c\u305e\u308c\u306b\u540d\u524d\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u540d\u524d\u306f\u30c9\u30c3\u30c8\u3092\u30bb\u30d1\u30ec\u30fc\u30bf\u3068\u3057\u305f\u968e\u5c64\u69cb\u9020\u3092\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001car\u3068\u3044\u3046\u540d\u524d\u306e\u30ed\u30ac\u30fc\u306fcar.engine\u3068\u3044\u3046\u30ed\u30ac\u30fc\u306e\u89aa\u3068\u306a\u308a\u307e\u3059\u3002\u524d\u306e\u30da\u30fc\u30b8\u3067\u3082\u8aac\u660e\u3057\u307e\u3057\u305f\u304c\u3001\u30ed\u30ac\u30fc\u306e\u540d\u524d\u306fgetLogger\u306e\u5f15\u6570\u3067\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport logging\r\n\r\n# \u30ed\u30ac\u30fc1\u3092\u53d6\u5f97\r\nlogger1 = logging.getLogger('parent')\r\nlogger1.setLevel(logging.DEBUG)\r\n\r\n# \u30cf\u30f3\u30c9\u30e9\u30fc1\u3092\u4f5c\u6210\u3059\u308b\r\nh1 = logging.StreamHandler()\r\nh1.setLevel(logging.DEBUG)\r\n\r\n# \u30cf\u30f3\u30c9\u30e9\u30fc1\u306b\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\r\nh1.setFormatter(logging.Formatter('\u30d5\u30a9\u30fc\u30de\u30c3\u30c81 %(message)s'))\r\n\r\n# \u30ed\u30ac\u30fc1\u306b\u30cf\u30f3\u30c9\u30e9\u30fc1\u3092\u8a2d\u5b9a\u3059\u308b\r\nlogger1.addHandler(h1)\r\n\r\n# 2\u500b\u3081\u306e\u30ed\u30ac\u30fc\u3002\u30ed\u30ac\u30fc2\u3092\u53d6\u5f97\u3002\u30cf\u30f3\u30c9\u30e9\u30fc\u306f\u8a2d\u5b9a\u3057\u306a\u3044\u3002 \r\nlogger2 = logging.getLogger('parent.childe')\r\n\r\n# \u51fa\u529b \r\nlogger2.error('\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8')\r\n\r\n<\/pre>\n<p>\u89aa\u5b50\u95a2\u4fc2\u306b\u3042\u308b\u30ed\u30ac\u30fc1\u3068\u30ed\u30ac\u30fc2\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u30ed\u30ac\u30fc2\u306b\u306f\u30cf\u30f3\u30c9\u30e9\u30fc\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u306a\u3044\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u30ed\u30ac\u30fc1\u306b\u8a2d\u5b9a\u3057\u305f\u30cf\u30f3\u30c9\u30e9\u306e\u8a2d\u5b9a\u304c\u52b9\u3044\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u30ed\u30ac\u30fc1\u306e\u540d\u524d\u304cparent\u3067\u3001\u30ed\u30ac\u30fc2\u306e\u540d\u524d\u304cparent.childe\u3067\u89aa\u5b50\u95a2\u4fc2\u306b\u3042\u308b\u305f\u3081\u3067\u3059\u3002\u307e\u305f\u3001\u5b50\u30ed\u30ac\u30fc\u306b\u5bfe\u3057\u3066addHandler\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u7279\u5b9a\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u51e6\u7406\u3060\u3051\u91cd\u70b9\u7684\u306b\u5225\u9014\u30ed\u30b0\u51fa\u529b\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30ed\u30ac\u30fc\u306e\u968e\u5c64\u69cb\u9020\u306e\u30c8\u30c3\u30d7\u306f\u3001\u30eb\u30fc\u30c8\u30ed\u30ac\u30fc\u3068\u547c\u3070\u308c\u3001\u30ed\u30b0\u51fa\u529b\u3067\u306froot\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u30eb\u30fc\u30c8\u30ed\u30ac\u30fc\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306fgetLogger\u3067\u7a7a\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002(root\u3068\u3044\u3046\u540d\u524d\u3067\u30ed\u30ac\u30fc\u3092\u53d6\u5f97\u3057\u3066\u3082\u3001\u30eb\u30fc\u30c8\u30ed\u30ac\u30fc\u306f\u53d6\u5f97\u3067\u304d\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002)\u30eb\u30fc\u30c8\u30ed\u30ac\u30fc\u306f\u5168\u3066\u306e\u30ed\u30ac\u30fc\u306e\u89aa\u306a\u306e\u3067\u3001\u3053\u3053\u306b\u8a2d\u5b9a\u3057\u305f\u5185\u5bb9\u306f\u5168\u3066\u306e\u30ed\u30ac\u30fc\u306b\u53cd\u6620\u3055\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30ed\u30ac\u30fc\u306e\u968e\u5c64 \u524d\u56de\u306e\u7d9a\u304d\u3067\u30ed\u30ac\u30fc\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u30ed\u30ac\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306f\u305d\u308c\u305e\u308c\u306b\u540d\u524d\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u540d\u524d\u306f\u30c9\u30c3\u30c8\u3092\u30bb\u30d1\u30ec\u30fc\u30bf\u3068\u3057\u305f\u968e\u5c64\u69cb\u9020\u3092\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001car\u3068\u3044\u3046\u540d\u524d\u306e\u30ed\u30ac\u30fc\u306fcar.engine...<\/p>\n","protected":false},"author":1,"featured_media":3633,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[144,211],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/718"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=718"}],"version-history":[{"count":3,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/718\/revisions"}],"predecessor-version":[{"id":3637,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/718\/revisions\/3637"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3633"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}