{"id":11355,"date":"2024-07-02T11:10:20","date_gmt":"2024-07-02T11:10:20","guid":{"rendered":"https:\/\/shivlab.com\/blog\/\/"},"modified":"2024-07-02T11:10:20","modified_gmt":"2024-07-02T11:10:20","slug":"logging-with-python-and-loguru-a-step-by-step-guide","status":"publish","type":"post","link":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/","title":{"rendered":"Logging with Python and Loguru: A Step-by-Step Guide"},"content":{"rendered":"<p>Logging is a crucial aspect of any robust Python application, offering invaluable insights for debugging, monitoring, and maintaining your software. The Loguru library simplifies logging in Python, making it more powerful and user-friendly. This guide will walk you through everything you need to know about using Loguru, from installation to advanced features like log rotation and colored terminal logging. Whether you&#8217;re working with a small script or a large application, this guide is your comprehensive resource.<\/p>\n<h2><strong>Installation<\/strong><\/h2>\n<hr \/>\n<p>Before we dive into the features of Loguru, let&#8217;s start with the installation process. <a href=\"https:\/\/loguru.readthedocs.io\/en\/stable\/\" target=\"_blank\" rel=\"noopener\">Installing Loguru<\/a> is straightforward and can be done using pip, the Python package installer. Here\u2019s how you can install it:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">pip install loguru<\/pre>\n<p>Once Loguru is installed, you are ready to integrate it into your Python projects. As a <a href=\"http:\/\/167.86.116.248\/shivlab\/python-development-services\/\">Python development company<\/a> in the USA, adopting Loguru can significantly enhance your logging capabilities, making your development and debugging processes smoother and more efficient.<\/p>\n<h2><strong>Logging Made Simple<\/strong><\/h2>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11378\" src=\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Logging-Made-Simple.jpg\" alt=\"Logging Made Simple\" width=\"950\" height=\"564\" srcset=\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Logging-Made-Simple.jpg 950w, http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Logging-Made-Simple-300x178.jpg 300w, http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Logging-Made-Simple-768x456.jpg 768w\" sizes=\"auto, (max-width: 950px) 100vw, 950px\" \/><\/p>\n<p>Loguru aims to simplify logging in Python, offering an easy-to-use interface. Here&#8217;s a basic example to get you started:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfrom loguru import logger\r\n\r\nlogger.info(&quot;This is an info message&quot;)\r\nlogger.debug(&quot;This is a debug message&quot;)\r\nlogger.error(&quot;This is an error message&quot;)\r\n<\/pre>\n<p>Unlike the standard logging module, Loguru doesn&#8217;t require much configuration. It&#8217;s ready to use right out of the box, making it ideal for developers who want to quickly implement logging without extensive setup. This simplicity allows you to focus on writing code rather than configuring your logging system.<\/p>\n<p>Loguru&#8217;s default logger writes to stderr and formats the log messages in a readable manner. However, you can customize it to suit your specific needs. For example, you can change the log level dynamically:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nlogger.remove()\r\nlogger.add(sys.stderr, level=&quot;DEBUG&quot;)\r\n<\/pre>\n<h2><strong>Handlers and Formatting<\/strong><\/h2>\n<hr \/>\n<p>Loguru provides flexible options for configuring log handlers and formatting log messages. Handlers determine where your logs go, such as to a file, an external logging service, or even a custom handler you define. Formatting allows you to customize the appearance of your log messages, making them easier to read and analyze.<\/p>\n<h3><strong><span style=\"color: #ff8625;\">#<\/span> Adding a File Handler:<\/strong><\/h3>\n<p>To write logs to a file, you can add a file handler. Here\u2019s an example:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;file.log&quot;, rotation=&quot;10 MB&quot;)<\/pre>\n<p>This will write log messages to file.log, and automatically rotate the file when it reaches 10 MB in size.<\/p>\n<h3><strong><span style=\"color: #ff8625;\">#<\/span> Custom Formatting:<\/strong><\/h3>\n<p>Customizing the format of your log messages is simple with Loguru. You can specify the format string when adding a handler:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;file.log&quot;, format=&quot;{time} {level} {message}&quot;)<\/pre>\n<p>This will format each log message to include the time, log level, and message. You can also include other attributes such as the filename, function name, and line number.<\/p>\n<h3><strong><span style=\"color: #ff8625;\">#<\/span> Multiple Handlers:<\/strong><\/h3>\n<p>Loguru allows you to configure multiple handlers, each with different formats and destinations. For example, you can log error messages to a file while logging info messages to the console:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nlogger.add(&quot;error.log&quot;, level=&quot;ERROR&quot;, format=&quot;{time} {level} {message}&quot;)\r\nlogger.add(sys.stdout, level=&quot;INFO&quot;, format=&quot;{time} {message}&quot;)\r\n<\/pre>\n<p>This flexibility ensures your logs are tailored to your needs, whether you need detailed logs for debugging or high-level summaries for monitoring.<\/p>\n<h2><strong>Catching Exceptions<\/strong><\/h2>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11380\" src=\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Catching-Exceptions.jpg\" alt=\"Catching Exceptions\" width=\"950\" height=\"564\" srcset=\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Catching-Exceptions.jpg 950w, http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Catching-Exceptions-300x178.jpg 300w, http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Catching-Exceptions-768x456.jpg 768w\" sizes=\"auto, (max-width: 950px) 100vw, 950px\" \/><\/p>\n<p>One of Loguru&#8217;s standout features is its ability to catch exceptions effortlessly. By using the catch decorator, you can log exceptions without cluttering your code with try-except blocks. This makes your code cleaner and more maintainable.<\/p>\n<p>Here\u2019s an example:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfrom loguru import logger\r\n\r\n@logger.catch\r\ndef divide(a, b):\r\n    return a \/ b\r\n\r\ndivide(10, 0)\r\n<\/pre>\n<p>When an exception occurs, Loguru logs the traceback, helping you quickly identify and resolve issues. This is particularly useful for functions that perform critical operations, as it ensures any errors are logged automatically.<\/p>\n<p>You can also use logger.catch as a context manager to log exceptions in a specific block of code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nwith logger.catch():\r\n    result = divide(10, 0)\r\n<\/pre>\n<h2><strong>Terminal Logging with Color<\/strong><\/h2>\n<hr \/>\n<p>Loguru supports colorful terminal logging, making it easier to distinguish between different log levels. This feature is especially useful during development and debugging, as it allows you to quickly identify important messages.<\/p>\n<p>Here\u2019s how you can add color to your log messages:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nlogger.info(&quot;&lt;green&gt;This is an info message&lt;\/green&gt;&quot;)\r\nlogger.error(&quot;&lt;red&gt;This is an error message&lt;\/red&gt;&quot;)\r\n<\/pre>\n<p>With color-coded logs, you can quickly spot critical issues or important information, enhancing your productivity. Loguru supports a variety of color codes and styles, allowing you to customize your log messages to fit your preferences.<\/p>\n<h2><strong>Easy Log Rotation<\/strong><\/h2>\n<hr \/>\n<p>Log rotation is crucial for managing log file sizes and ensuring that logs don&#8217;t consume too much disk space. Loguru makes log rotation simple with its built-in rotation feature.<\/p>\n<p>Here\u2019s an example of how to set up log rotation:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;app.log&quot;, rotation=&quot;1 week&quot;)<\/pre>\n<p>This will create a new log file every week, archiving the old files. You can specify various rotation criteria, such as file size, time interval, or even a custom function. For example, to rotate logs based on file size:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;app.log&quot;, rotation=&quot;500 MB&quot;)<\/pre>\n<p>Or to rotate logs daily:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;app.log&quot;, rotation=&quot;00:00&quot;)<\/pre>\n<h2><strong>Advanced Features<\/strong><\/h2>\n<hr \/>\n<p>Loguru offers several advanced features that can further enhance your logging setup. Here are a few examples:<\/p>\n<h3><strong><span style=\"color: #ff8625;\">#<\/span> Backtrace and Diagnostics:<\/strong><\/h3>\n<p>Loguru can include a backtrace and diagnostics in your log messages, providing more context for debugging. This is particularly useful for understanding the sequence of events leading up to an error.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nlogger.add(&quot;file.log&quot;, backtrace=True, diagnose=True)\r\n<\/pre>\n<h3><strong><span style=\"color: #ff8625;\">#<\/span> Serialization:<\/strong><\/h3>\n<p>Loguru can serialize your log messages to JSON, making it easier to integrate with log management systems like ELK (Elasticsearch, Logstash, and Kibana).<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;file.json&quot;, serialize=True)<\/pre>\n<h3><strong><span style=\"color: #ff8625;\">#<\/span> Asynchronous Logging:<\/strong><\/h3>\n<p>For applications with high logging throughput, Loguru supports asynchronous logging, ensuring that logging operations do not block your main application thread.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">logger.add(&quot;file.log&quot;, enqueue=True)<\/pre>\n<h4><strong>Conclusion<\/strong><\/h4>\n<hr \/>\n<p>Loguru is a powerful and user-friendly logging library for Python. Its simplicity and advanced features make it an excellent choice for both beginners and experienced developers. By following this guide, you can easily integrate Loguru into your projects, improving your logging capabilities and making your development process smoother.<\/p>\n<p>For <a href=\"http:\/\/167.86.116.248\/shivlab\/python-development-company-usa\/\">Python development companies in USA<\/a>, leveraging Loguru can provide significant benefits in terms of monitoring and maintaining your applications. Whether you&#8217;re debugging issues or tracking application performance, Loguru&#8217;s features make logging an effortless and efficient process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Improve your Python logging with Loguru. This detailed guide covers installation, simple logging, handlers, formatting, exception handling, colorful terminal logs, and easy log rotation, providing a comprehensive resource for developers aiming to streamline their logging processes.<\/p>\n","protected":false},"author":4,"featured_media":11377,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-11355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Logging with Python and Loguru: A Step-by-Step Guide<\/title>\n<meta name=\"description\" content=\"Master logging in Python with Loguru. This guide covers installation, simple logging, handlers, formatting, exceptions, colored terminal logs, and log rotation for robust applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logging with Python and Loguru: A Step-by-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Master logging in Python with Loguru. This guide covers installation, simple logging, handlers, formatting, exceptions, colored terminal logs, and log rotation for robust applications.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Shiv Technolabs Pvt. Ltd.\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ShivTechnolabs\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/dipen.majithiya\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-02T11:10:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1140\" \/>\n\t<meta property=\"og:image:height\" content=\"762\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Dipen Majithiya\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dip_majithiya\" \/>\n<meta name=\"twitter:site\" content=\"@Shiv_Technolabs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dipen Majithiya\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\"},\"author\":{\"name\":\"Dipen Majithiya\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#\/schema\/person\/656b1fcc45a591961e3f3b061cd03206\"},\"headline\":\"Logging with Python and Loguru: A Step-by-Step Guide\",\"datePublished\":\"2024-07-02T11:10:20+00:00\",\"dateModified\":\"2024-07-02T11:10:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\"},\"wordCount\":1172,\"publisher\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#organization\"},\"image\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png\",\"articleSection\":[\"Web Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\",\"url\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\",\"name\":\"Logging with Python and Loguru: A Step-by-Step Guide\",\"isPartOf\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png\",\"datePublished\":\"2024-07-02T11:10:20+00:00\",\"dateModified\":\"2024-07-02T11:10:20+00:00\",\"description\":\"Master logging in Python with Loguru. This guide covers installation, simple logging, handlers, formatting, exceptions, colored terminal logs, and log rotation for robust applications.\",\"breadcrumb\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage\",\"url\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png\",\"contentUrl\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png\",\"width\":1140,\"height\":762,\"caption\":\"Python and Loguru\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/167.86.116.248\/shivlab\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logging with Python and Loguru: A Step-by-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#website\",\"url\":\"http:\/\/167.86.116.248\/shivlab\/\",\"name\":\"Shiv Technolabs Pvt. Ltd.\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/167.86.116.248\/shivlab\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#organization\",\"name\":\"Shiv Technolabs Pvt. Ltd\",\"url\":\"http:\/\/167.86.116.248\/shivlab\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/11\/stl-logo1.png\",\"contentUrl\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/11\/stl-logo1.png\",\"width\":1280,\"height\":371,\"caption\":\"Shiv Technolabs Pvt. Ltd\"},\"image\":{\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ShivTechnolabs\/\",\"https:\/\/x.com\/Shiv_Technolabs\",\"https:\/\/www.linkedin.com\/company\/shivtechnolabs\/\",\"https:\/\/www.instagram.com\/shivtechnolabs\/\",\"https:\/\/in.pinterest.com\/ShivTechnolabs\/\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#\/schema\/person\/656b1fcc45a591961e3f3b061cd03206\",\"name\":\"Dipen Majithiya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/167.86.116.248\/shivlab\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/09\/02_emp_pic-dipen-150x150.png\",\"contentUrl\":\"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/09\/02_emp_pic-dipen-150x150.png\",\"caption\":\"Dipen Majithiya\"},\"description\":\"I am a proactive chief technology officer (CTO) of Shiv Technolabs. I have 10+ years of experience in eCommerce, mobile apps, and web development in the tech industry. I am Known for my strategic insight and have mastered core technical domains. I have empowered numerous business owners with bespoke solutions, fearlessly taking calculated risks and harnessing the latest technological advancements.\",\"sameAs\":[\"http:\/\/167.86.116.248\/shivlab\/\",\"https:\/\/www.facebook.com\/dipen.majithiya\",\"https:\/\/www.linkedin.com\/in\/dipenmajithiya\/\",\"https:\/\/x.com\/dip_majithiya\"],\"url\":\"http:\/\/167.86.116.248\/shivlab\/author\/dipen_majithiya\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logging with Python and Loguru: A Step-by-Step Guide","description":"Master logging in Python with Loguru. This guide covers installation, simple logging, handlers, formatting, exceptions, colored terminal logs, and log rotation for robust applications.","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":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/","og_locale":"en_US","og_type":"article","og_title":"Logging with Python and Loguru: A Step-by-Step Guide","og_description":"Master logging in Python with Loguru. This guide covers installation, simple logging, handlers, formatting, exceptions, colored terminal logs, and log rotation for robust applications.","og_url":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/","og_site_name":"Shiv Technolabs Pvt. Ltd.","article_publisher":"https:\/\/www.facebook.com\/ShivTechnolabs\/","article_author":"https:\/\/www.facebook.com\/dipen.majithiya","article_published_time":"2024-07-02T11:10:20+00:00","og_image":[{"width":1140,"height":762,"url":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png","type":"image\/png"}],"author":"Dipen Majithiya","twitter_card":"summary_large_image","twitter_creator":"@dip_majithiya","twitter_site":"@Shiv_Technolabs","twitter_misc":{"Written by":"Dipen Majithiya","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#article","isPartOf":{"@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/"},"author":{"name":"Dipen Majithiya","@id":"http:\/\/167.86.116.248\/shivlab\/#\/schema\/person\/656b1fcc45a591961e3f3b061cd03206"},"headline":"Logging with Python and Loguru: A Step-by-Step Guide","datePublished":"2024-07-02T11:10:20+00:00","dateModified":"2024-07-02T11:10:20+00:00","mainEntityOfPage":{"@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/"},"wordCount":1172,"publisher":{"@id":"http:\/\/167.86.116.248\/shivlab\/#organization"},"image":{"@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage"},"thumbnailUrl":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png","articleSection":["Web Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/","url":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/","name":"Logging with Python and Loguru: A Step-by-Step Guide","isPartOf":{"@id":"http:\/\/167.86.116.248\/shivlab\/#website"},"primaryImageOfPage":{"@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage"},"image":{"@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage"},"thumbnailUrl":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png","datePublished":"2024-07-02T11:10:20+00:00","dateModified":"2024-07-02T11:10:20+00:00","description":"Master logging in Python with Loguru. This guide covers installation, simple logging, handlers, formatting, exceptions, colored terminal logs, and log rotation for robust applications.","breadcrumb":{"@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#primaryimage","url":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png","contentUrl":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png","width":1140,"height":762,"caption":"Python and Loguru"},{"@type":"BreadcrumbList","@id":"http:\/\/167.86.116.248\/shivlab\/blog\/logging-with-python-and-loguru-a-step-by-step-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/167.86.116.248\/shivlab\/"},{"@type":"ListItem","position":2,"name":"Logging with Python and Loguru: A Step-by-Step Guide"}]},{"@type":"WebSite","@id":"http:\/\/167.86.116.248\/shivlab\/#website","url":"http:\/\/167.86.116.248\/shivlab\/","name":"Shiv Technolabs Pvt. Ltd.","description":"","publisher":{"@id":"http:\/\/167.86.116.248\/shivlab\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/167.86.116.248\/shivlab\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/167.86.116.248\/shivlab\/#organization","name":"Shiv Technolabs Pvt. Ltd","url":"http:\/\/167.86.116.248\/shivlab\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/167.86.116.248\/shivlab\/#\/schema\/logo\/image\/","url":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/11\/stl-logo1.png","contentUrl":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/11\/stl-logo1.png","width":1280,"height":371,"caption":"Shiv Technolabs Pvt. Ltd"},"image":{"@id":"http:\/\/167.86.116.248\/shivlab\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ShivTechnolabs\/","https:\/\/x.com\/Shiv_Technolabs","https:\/\/www.linkedin.com\/company\/shivtechnolabs\/","https:\/\/www.instagram.com\/shivtechnolabs\/","https:\/\/in.pinterest.com\/ShivTechnolabs\/"]},{"@type":"Person","@id":"http:\/\/167.86.116.248\/shivlab\/#\/schema\/person\/656b1fcc45a591961e3f3b061cd03206","name":"Dipen Majithiya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/167.86.116.248\/shivlab\/#\/schema\/person\/image\/","url":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/09\/02_emp_pic-dipen-150x150.png","contentUrl":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2022\/09\/02_emp_pic-dipen-150x150.png","caption":"Dipen Majithiya"},"description":"I am a proactive chief technology officer (CTO) of Shiv Technolabs. I have 10+ years of experience in eCommerce, mobile apps, and web development in the tech industry. I am Known for my strategic insight and have mastered core technical domains. I have empowered numerous business owners with bespoke solutions, fearlessly taking calculated risks and harnessing the latest technological advancements.","sameAs":["http:\/\/167.86.116.248\/shivlab\/","https:\/\/www.facebook.com\/dipen.majithiya","https:\/\/www.linkedin.com\/in\/dipenmajithiya\/","https:\/\/x.com\/dip_majithiya"],"url":"http:\/\/167.86.116.248\/shivlab\/author\/dipen_majithiya\/"}]}},"jetpack_featured_media_url":"http:\/\/167.86.116.248\/shivlab\/wp-content\/uploads\/2024\/07\/Python-and-Loguru.png","_links":{"self":[{"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/posts\/11355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/comments?post=11355"}],"version-history":[{"count":5,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/posts\/11355\/revisions"}],"predecessor-version":[{"id":11381,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/posts\/11355\/revisions\/11381"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/media\/11377"}],"wp:attachment":[{"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/media?parent=11355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/categories?post=11355"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/167.86.116.248\/shivlab\/wp-json\/wp\/v2\/tags?post=11355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}