{"id":135360,"date":"2024-09-06T11:43:21","date_gmt":"2024-09-06T06:13:21","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=135360"},"modified":"2024-09-06T11:43:22","modified_gmt":"2024-09-06T06:13:22","slug":"logger-hierarchies-and-name","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/","title":{"rendered":"Logger Hierarchies and name"},"content":{"rendered":"\n<p>In Python&#8217;s logging module, loggers are organized in a hierarchical structure. This hierarchy allows you to control the logging level for different parts of your application. The <code class=\"\">__name__<\/code> attribute is used to identify the current module or package, and it&#8217;s often used to create unique logger names.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating Logger Hierarchies<\/strong><\/h2>\n\n\n\n<p>When you create a logger using <code class=\"\">getLogger(__name__)<\/code>, the logger&#8217;s name is derived from the current module&#8217;s <code class=\"\">__name__<\/code> attribute. This creates a hierarchical structure, where loggers with longer names are children of loggers with shorter names. For example, if you have a module named <code class=\"\">app.utils<\/code>, the logger created within that module will have the name <code class=\"\">app.utils<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Propagation<\/strong><\/h2>\n\n\n\n<p>By default, log messages from a child logger are propagated to its parent loggers. This means that if you set the logging level for a parent logger, it will affect all of its child loggers.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import logging\n\nlogger1 = logging.getLogger(\"app.module1\")\nlogger2 = logging.getLogger(\"app.module2\")\n\nlogger1.setLevel(logging.DEBUG)\nlogger2.setLevel(logging.INFO)\n\nlogger1.debug(\"This message will be logged\")\nlogger2.debug(\"This message will not be logged\")\n<\/code><\/pre>\n\n\n\n<p>In this example, <code class=\"\">logger1<\/code> is a parent of <code class=\"\">logger2<\/code>. Since <code class=\"\">logger1<\/code> has a logging level of <code class=\"\">DEBUG<\/code>, all messages from <code class=\"\">logger1<\/code> and its children will be logged. However, because <code class=\"\">logger2<\/code> has a logging level of <code class=\"\">INFO<\/code>, messages with a level below <code class=\"\">INFO<\/code> (such as <code class=\"\">DEBUG<\/code>) will not be logged by <code class=\"\">logger2<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Disabling Propagation<\/strong><\/h2>\n\n\n\n<p>To prevent log messages from propagating to parent loggers, you can set the <code class=\"\">propagate<\/code> attribute of a logger to <code class=\"\">False<\/code>:<\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>logger2.propagate = False\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using Logger Hierarchies Effectively<\/strong><\/h2>\n\n\n\n<p>By understanding logger hierarchies and the <code class=\"\">__name__<\/code> attribute, you can effectively control the logging behavior in your FastAPI applications. You can create separate loggers for different parts of your application and set appropriate logging levels to capture the information you need. This can help you debug issues more efficiently and maintain a clean and organized logging setup.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python&#8217;s logging module, loggers are organized in a hierarchical structure. This hierarchy allows you to control the logging level for different parts of your application. The __name__ attribute is used to identify the current module or package, and it&#8217;s often used to create unique logger names. Creating Logger Hierarchies When you create a logger&#8230;<\/p>\n","protected":false},"author":16,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-135360","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Logger Hierarchies and name - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logger Hierarchies and name - Tutorial\" \/>\n<meta property=\"og:description\" content=\"In Python&#8217;s logging module, loggers are organized in a hierarchical structure. This hierarchy allows you to control the logging level for different parts of your application. The __name__ attribute is used to identify the current module or package, and it&#8217;s often used to create unique logger names. Creating Logger Hierarchies When you create a logger...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-06T06:13:22+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/\",\"name\":\"Logger Hierarchies and name - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2024-09-06T06:13:21+00:00\",\"dateModified\":\"2024-09-06T06:13:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logger Hierarchies and name\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logger Hierarchies and name - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/","og_locale":"en_US","og_type":"article","og_title":"Logger Hierarchies and name - Tutorial","og_description":"In Python&#8217;s logging module, loggers are organized in a hierarchical structure. This hierarchy allows you to control the logging level for different parts of your application. The __name__ attribute is used to identify the current module or package, and it&#8217;s often used to create unique logger names. Creating Logger Hierarchies When you create a logger...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-09-06T06:13:22+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/","name":"Logger Hierarchies and name - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2024-09-06T06:13:21+00:00","dateModified":"2024-09-06T06:13:22+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/logger-hierarchies-and-name\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Logger Hierarchies and name"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/135360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=135360"}],"version-history":[{"count":2,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/135360\/revisions"}],"predecessor-version":[{"id":135399,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/135360\/revisions\/135399"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=135360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=135360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=135360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}