{"id":28793,"date":"2023-07-03T06:32:07","date_gmt":"2023-07-03T06:32:07","guid":{"rendered":"https:\/\/www.confianzit.com\/cit-blog\/?p=28793"},"modified":"2023-07-03T10:10:36","modified_gmt":"2023-07-03T10:10:36","slug":"odoo-logging","status":"publish","type":"post","link":"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/","title":{"rendered":"Using Logging in Odoo 16"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.16&#8243; global_colors_info=&#8221;{}&#8221;][et_pb_row column_structure=&#8221;3_5,2_5&#8243; _builder_version=&#8221;4.21.0&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;3_5&#8243; _builder_version=&#8221;4.16&#8243; custom_padding=&#8221;|||&#8221; global_colors_info=&#8221;{}&#8221; custom_padding__hover=&#8221;|||&#8221;][et_pb_text module_class=&#8221;blog-left-content&#8221; _builder_version=&#8221;4.21.0&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#What_does_logging_mean\" title=\"What does logging mean?\">What does logging mean?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Why_is_logging_required\" title=\"Why is logging required?\">Why is logging required?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Steps_to_perform_logging_in_Odoo_16\" title=\"Steps to perform logging in Odoo 16\">Steps to perform logging in Odoo 16<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Things_to_consider_when_logging_data\" title=\"Things to consider when logging data\">Things to consider when logging data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Hire_Odoo_Developer_from_Confianz_Global\" title=\"Hire Odoo Developer from Confianz Global\">Hire Odoo Developer from Confianz Global<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Talk_to_our_experts_now\" title=\"    Talk to our experts now  \">    Talk to our experts now  <\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/#Talk_To_Our_Experts_Now\" title=\"Talk To Our Experts Now\n\t\">Talk To Our Experts Now\n\t<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"What_does_logging_mean\"><\/span><b>What does logging mean?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><b><\/b><\/p>\n<p><span style=\"font-weight: 400;\">Logging is an operation in Odoo to check, analyze, and rectify errors in the Odoo server. It is an inherent functionality from Python that allows developers to output certain data on a terminal window, or into a log file for future analysis.\u00a0<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_is_logging_required\"><\/span><b>Why is logging required?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><b><\/b><\/p>\n<p><span style=\"font-weight: 400;\">Logging can be added to any module during the development stages, where the developers find the need to analyze certain data. Such information can be used to debug errors or pinpoint incorrect values getting passed over into APIs and across modules. This helps in perfecting <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-apps\"><span style=\"font-weight: 400;\">Odoo modules<\/span><\/a><span style=\"font-weight: 400;\"> and keeping the business functioning as expected.<\/span><b>\u00a0<\/b><\/p>\n<p><span style=\"font-weight: 400;\">One of the key advantages of having logging in place is to determine user access. Every time a user authenticates into the system, a log entry is made. This helps administrators quickly identify breaching and hacking events, along with unauthorized access attempts. Logging also keeps track of timestamps and IP addresses from where the event has occurred. This helps in the traceability of events happening on the <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo system<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2023\/07\/Using-Logging-in-Odoo-16-ITC.jpg\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Steps_to_perform_logging_in_Odoo_16\"><\/span><b>Steps to perform logging in <\/b><a href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-16-features\/\"><b>Odoo 16<\/b><\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><b><\/b><\/p>\n<p><span style=\"font-weight: 400;\">1. Import: The first step if we want to log any data is to import the Logging module from the standard libraries provided by Python into their code. This step is executed with a simple import statement as follows:<\/span><\/p>\n<pre class=\"wp-block-code\"><span style=\"font-weight: 400;\">import logging<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">With the logging module now ready to use, we can create an object for logging inside the Service request module file of Odoo by invoking the getLogger method as<\/span><\/p>\n<pre class=\"wp-block-code\"><span style=\"font-weight: 400;\">_logger = logging.getLogger(__name__)<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">2. Add loggers in code: With the logging object available, we can now simply start adding log statements into our module. There are 5 different levels of logging that we can do, which are:<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">a. DEBUG: _logger.debug is used to display information as a debug message<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">b. INFO: _logger.info is used to categorize the log as an info message<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">c. WARNING: _logger.warning is used for logging messages as a warning<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">d. ERROR:_logger.error Error levels are used in highlighting any error-based data<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">e. CRITICAL: _logger.critical is the highest level of logging, generally used to symbolize failure in the system<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Verify Odoo log output: Let&#8217;s take a closer look at these different levels and how they function when a request date field is modified in our Service Request module:<\/span><\/p>\n<p><img decoding=\"async\" style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2023\/07\/bimg1.png\" \/><\/p>\n<p><span style=\"font-weight: 400;\">To verify these log messages, we need to view them on the server console:<\/span><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2023\/07\/bimg2.png\" \/><\/p>\n<p><span style=\"font-weight: 400;\">4. Additional configurations: In the above example, we have all 5 levels enabled, thereby displaying all the loggers. However, in the real world, there would only be certain log categories that will be enabled, and this is done using some additional configurations that can be added in the odoo.conf file:<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">a. logfile = odoo.log \/\/ All log information will be stored on a file called odoo.log.<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">b. log_handler = : DEBUG \/\/ This will enable all Debug category logs to be displayed<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">For example, if we require only an ERROR level for the module service_request only, then we can run as shown below:<\/span><\/p>\n<pre class=\"wp-block-code\"><span style=\"font-weight: 400;\">log_handler=odoo.ServiceRequest:ERROR<\/span><\/pre>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">c. log_level = critical \/\/ Specify the critical logging level for all modules. However, this has been deprecated and replaced with log_handler.<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">d. log_db_level = info \/\/ Set the info Logging level for the database.<\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">e. log_db = true \/\/ When using the above and logging database execution statements, we need to set log_db as true.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Things_to_consider_when_logging_data\"><\/span><b>Things to consider when logging data<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><b><\/b><\/p>\n<p><span style=\"font-weight: 400;\">While logging is an extremely important and useful feature for all <\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><span style=\"font-weight: 400;\">developers<\/span><\/a><span style=\"font-weight: 400;\">, there are a few important things to consider:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Choose the correct category of log in the code: If we select an incorrect category, we might land up in a situation where we land up enabling unwanted information in the log<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Amount of logger statements: Avoid unnecessary logging of data, as it only slows down the application. It is important to know where log statements are most useful and add them there only.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Data being logged: A lot of data is client specific and sensitive as <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-apps\"><span style=\"font-weight: 400;\">Odoo modules<\/span><\/a><span style=\"font-weight: 400;\"> deal with Banking, Purchasing, Invoicing, etc. This means not everything can be added and displayed on logs, and it&#8217;s necessary to keep confidentiality in mind.<\/span><\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><b>Conclusion<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><b><\/b><\/p>\n<p><a href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/\"><span style=\"font-weight: 400;\">Odoo<\/span><\/a><span style=\"font-weight: 400;\"><a href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-logging\/\"> logging<\/a> is an essential part of the development process, and it helps in debugging and resolving issues quickly, identifying potential problems in the data flow. While the use of logging is an integral part of code, we always need to vary \u201cwhat and how much\u201d we are logging.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Hire_Odoo_Developer_from_Confianz_Global\"><\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><b>Hire Odoo Developer<\/b><\/a><b> from Confianz Global<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><b><\/b><\/p>\n<p><a href=\"https:\/\/www.confianzit.com\/\"><span style=\"font-weight: 400;\">Confianz Global\u00ae<\/span><\/a><span style=\"font-weight: 400;\"> is a software solutions company based in Charlotte, North Carolina. We specialize in providing development services to our clients. Operating from our headquarters in the United States, we take pride in offering highly skilled and <\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><span style=\"font-weight: 400;\">dedicated Odoo developers<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><span style=\"font-weight: 400;\">Odoo Functional Consultants<\/span><\/a><span style=\"font-weight: 400;\"> to cater to the unique needs of our customers. Our team of proficient Odoo programmers has successfully implemented <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo ERP<\/span><\/a><span style=\"font-weight: 400;\"> solutions for a wide range of businesses, spanning various industries, both within the United States and internationally. Through our extensive experience in executing <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo projects<\/span><\/a><span style=\"font-weight: 400;\">, we have garnered valuable insights and expertise in serving small and medium-sized businesses as well as large corporations.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We have a team of certified <a href=\"https:\/\/www.confianzit.com\/odoo\/consulting-services\">Odoo developers and <\/a><\/span><a href=\"https:\/\/www.confianzit.com\/odoo\/consulting-services\"><span style=\"font-weight: 400;\">consultants<\/span><\/a><span style=\"font-weight: 400;\"> who can help you with all your <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-customization\"><span style=\"font-weight: 400;\">Odoo ERP Customization<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-implementation\"><span style=\"font-weight: 400;\">Odoo implementation<\/span><\/a><span style=\"font-weight: 400;\"> needs. <\/span><a href=\"https:\/\/www.confianzit.com\/contact-us\"><span style=\"font-weight: 400;\">Call us<\/span><\/a><span style=\"font-weight: 400;\"> today!<\/span><\/p>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;2_5&#8243; _builder_version=&#8221;4.16&#8243; custom_padding=&#8221;|||&#8221; global_colors_info=&#8221;{}&#8221; custom_padding__hover=&#8221;|||&#8221;][et_pb_code _builder_version=&#8221;4.21.0&#8243; _module_preset=&#8221;default&#8221; animation_style=&#8221;bounce&#8221; animation_direction=&#8221;top&#8221; sticky_position=&#8221;top&#8221; sticky_offset_top=&#8221;20px&#8221; sticky_limit_bottom=&#8221;column&#8221; sticky_transition=&#8221;off&#8221; motion_trigger_start=&#8221;top&#8221; global_module=&#8221;2151&#8243; locked=&#8221;off&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<div class=\"blog-floating-form\"><!-- [et_pb_line_break_holder] -->  <\/p>\n<h4><span class=\"ez-toc-section\" id=\"Talk_to_our_experts_now\"><\/span><!-- [et_pb_line_break_holder] -->    Talk to our experts now<!-- [et_pb_line_break_holder] -->  <span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><!-- [et_pb_line_break_holder] -->  \n<div class=\"wpcf7 no-js\" id=\"wpcf7-f1888-o1\" lang=\"en-US\" dir=\"ltr\">\n<div class=\"screen-reader-response\"><p role=\"status\" aria-live=\"polite\" aria-atomic=\"true\"><\/p> <ul><\/ul><\/div>\n<form action=\"\/cit-blog\/wp-json\/wp\/v2\/posts\/28793#wpcf7-f1888-o1\" method=\"post\" class=\"wpcf7-form init\" aria-label=\"Contact form\" novalidate=\"novalidate\" data-status=\"init\">\n<div style=\"display: none;\">\n<input type=\"hidden\" name=\"_wpcf7\" value=\"1888\" \/>\n<input type=\"hidden\" name=\"_wpcf7_version\" value=\"5.8.6\" \/>\n<input type=\"hidden\" name=\"_wpcf7_locale\" value=\"en_US\" \/>\n<input type=\"hidden\" name=\"_wpcf7_unit_tag\" value=\"wpcf7-f1888-o1\" \/>\n<input type=\"hidden\" name=\"_wpcf7_container_post\" value=\"0\" \/>\n<input type=\"hidden\" name=\"_wpcf7_posted_data_hash\" value=\"\" \/>\n<input type=\"hidden\" name=\"_wpcf7_recaptcha_response\" value=\"\" \/>\n<\/div>\n<div class=\"form-block\" style=\"    background: #fff;\">\n\t<h3 style=\"    background: #0C2464;\n    border-bottom: 5px solid #cecece;\n    border-radius: 5px 5px 90px 90px;\n    margin: 0 auto;\n    text-align: center;\n    padding: 20px;\n    color: #fff;    margin-bottom: 15px;\"><span class=\"ez-toc-section\" id=\"Talk_To_Our_Experts_Now\"><\/span><b>Talk To Our Experts Now<\/b>\n\t<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\t<div style=\"padding:20px;\">\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"your-name\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-text wpcf7-validates-as-required your-name\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Name\" value=\"\" type=\"text\" name=\"your-name\" \/><\/span>\n\t\t<\/p>\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"your-email\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-email wpcf7-validates-as-required wpcf7-text wpcf7-validates-as-email your-email\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Email\" value=\"\" type=\"email\" name=\"your-email\" \/><\/span>\n\t\t<\/p>\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"your-number\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-tel wpcf7-validates-as-required wpcf7-text wpcf7-validates-as-tel your-number\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Phone Number\" value=\"\" type=\"tel\" name=\"your-number\" \/><\/span>\n\t\t<\/p>\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"message\"><textarea cols=\"40\" rows=\"10\" class=\"wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required form-message\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Message\" name=\"message\"><\/textarea><\/span>\n\t\t<\/p>\n\t<span class=\"wpcf7-form-control-wrap recaptcha\" data-name=\"recaptcha\"><span data-sitekey=\"6LfFkQATAAAAAIYlZ_UH9UozO-OLkpAaWPWx6QtM\" class=\"wpcf7-form-control wpcf7-recaptcha g-recaptcha\"><\/span>\r\n<noscript>\r\n\t<div class=\"grecaptcha-noscript\">\r\n\t\t<iframe loading=\"lazy\" src=\"https:\/\/www.google.com\/recaptcha\/api\/fallback?k=6LfFkQATAAAAAIYlZ_UH9UozO-OLkpAaWPWx6QtM\" frameborder=\"0\" scrolling=\"no\" width=\"310\" height=\"430\">\r\n\t\t<\/iframe>\r\n\t\t<textarea name=\"g-recaptcha-response\" rows=\"3\" cols=\"40\" placeholder=\"reCaptcha Response Here\">\r\n\t\t<\/textarea>\r\n\t<\/div>\r\n<\/noscript>\r\n<\/span>\n\t\t<div class=\"form-buttons\">\n\t\t\t<p><input class=\"wpcf7-form-control wpcf7-submit has-spinner\" type=\"submit\" value=\"Get a free quote\" \/>\n\t\t\t<\/p>\n\t\t<\/div>\n\t<\/div>\n<\/div><div class=\"wpcf7-response-output\" aria-hidden=\"true\"><\/div>\n<\/form>\n<\/div>\n<!-- [et_pb_line_break_holder] --><\/div>\n<p>[\/et_pb_code][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What does logging mean? Logging is an operation in Odoo to check, analyze, and rectify errors in the Odoo server. It is an inherent functionality from Python that allows developers to output certain data on a terminal window, or into a log file for future analysis.\u00a0 Why is logging required? Logging can be added to [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":28850,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"<h3><b>What does logging mean?<\/b><\/h3><p><span style=\"font-weight: 400;\">Logging is an operation in Odoo to check, analyze, and rectify errors in the Odoo server. It is an inherent functionality from Python that allows developers to output certain data on a terminal window, or into a log file for future analysis.\u00a0<\/span><\/p><h3><b>Why is logging required?<\/b><\/h3><p><span style=\"font-weight: 400;\">Logging can be added to any module during the development stages, where the developers find the need to analyze certain data. Such information can be used to debug errors or pinpoint incorrect values getting passed over into APIs and across modules. This helps in perfecting <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-apps\"><span style=\"font-weight: 400;\">Odoo modules<\/span><\/a><span style=\"font-weight: 400;\"> and keeping the business functioning as expected.<\/span><b>\u00a0<\/b><\/p><p><span style=\"font-weight: 400;\">One of the key advantages of having logging in place is to determine user access. Every time a user authenticates into the system, a log entry is made. This helps administrators quickly identify breaching and hacking events, along with unauthorized access attempts. Logging also keeps track of timestamps and IP addresses from where the event has occurred. This helps in the traceability of events happening on the <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo system<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p><h3><b>Steps to perform logging in <\/b><a href=\"https:\/\/www.confianzit.com\/cit-blog\/odoo-16-features\/\"><b>Odoo 16<\/b><\/a><\/h3><ol><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Import: The first step if we want to log any data is to import the Logging module from the standard libraries provided by Python into their code. This step is executed with a simple import statement as follows:<\/span><\/li><\/ol><p><span style=\"font-weight: 400;\">import logging<\/span><\/p><p><span style=\"font-weight: 400;\">With the logging module now ready to use, we can create an object for logging inside the Service request module file of Odoo by invoking the getLogger method as<\/span><\/p><p><span style=\"font-weight: 400;\">_logger = logging.getLogger(__name__)<\/span><\/p><ol><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Add loggers in code: With the logging object available, we can now simply start adding log statements into our module. There are 5 different levels of logging that we can do, which are:<\/span><ol><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">DEBUG: _logger.debug is used to display information as a debug message<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">INFO: _logger.info is used to categorize the log as an info message<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">WARNING: _logger.warning is used for logging messages as a warning<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">ERROR:_logger.error Error levels are used in highlighting any error-based data<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">CRITICAL: _logger.critical is the highest level of logging, generally used to symbolize failure in the system<\/span><\/li><\/ol><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Verify Odoo log output: Let's take a closer look at these different levels and how they function when a request date field is modified in our Service Request module:<\/span><\/li><\/ol><p><span style=\"font-weight: 400;\">To verify these log messages, we need to view them on the server console:<\/span><\/p><p>Additional configurations: In the above example, we have all 5 levels enabled, thereby displaying all the loggers. However, in the real world, there would only be certain log categories that will be enabled, and this is done using some additional configurations that can be added in the odoo.conf file:<\/p><ol><li style=\"font-weight: 400;\"><ol><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">logfile = odoo.log \/\/ All log information will be stored on a file called odoo.log.<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">log_handler = : DEBUG \/\/ This will enable all Debug category logs to be displayed<\/span><\/li><\/ol><\/li><\/ol><p><span style=\"font-weight: 400;\">For example, if we require only an ERROR level for the module service_request only, then we can run as shown below:<\/span><\/p><p><span style=\"font-weight: 400;\">log_handler=odoo.ServiceRequest:ERROR<\/span><\/p><ol><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">log_level = critical \/\/ Specify the critical logging level for all modules. However, this has been deprecated and replaced with log_handler.<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">log_db_level = info \/\/ Set the info Logging level for the database.<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">log_db = true \/\/ When using the above and logging database execution statements, we need to set log_db as true.<\/span><\/li><\/ol><h3><b>Things to consider when logging data<\/b><\/h3><p><span style=\"font-weight: 400;\">While logging is an extremely important and useful feature for all <\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><span style=\"font-weight: 400;\">developers<\/span><\/a><span style=\"font-weight: 400;\">, there are a few important things to consider:<\/span><\/p><ul><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Choose the correct category of log in the code: If we select an incorrect category, we might land up in a situation where we land up enabling unwanted information in the log<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Amount of logger statements: Avoid unnecessary logging of data, as it only slows down the application. It is important to know where log statements are most useful and add them there only.<\/span><\/li><li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Data being logged: A lot of data is client specific and sensitive as <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-apps\"><span style=\"font-weight: 400;\">Odoo modules<\/span><\/a><span style=\"font-weight: 400;\"> deal with Banking, Purchasing, Invoicing, etc. This means not everything can be added and displayed on logs, and it's necessary to keep confidentiality in mind.<\/span><\/li><\/ul><h3><b>Conclusion<\/b><\/h3><p><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo<\/span><\/a><span style=\"font-weight: 400;\"> logging is an essential part of the development process, and it helps in debugging and resolving issues quickly, identifying potential problems in the data flow. While the use of logging is an integral part of code, we always need to vary \u201cwhat and how much\u201d we are logging.<\/span><\/p><h3><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><b>Hire Odoo Developer<\/b><\/a><b> from Confianz Global<\/b><\/h3><p><a href=\"https:\/\/www.confianzit.com\/\"><span style=\"font-weight: 400;\">Confianz Global\u00ae<\/span><\/a><span style=\"font-weight: 400;\"> is a software solutions company based in Charlotte, North Carolina. We specialize in providing development services to our clients. Operating from our headquarters in the United States, we take pride in offering highly skilled and <\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><span style=\"font-weight: 400;\">dedicated Odoo developers<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/www.confianzit.com\/hire-odoo-developer\"><span style=\"font-weight: 400;\">Odoo Functional Consultants<\/span><\/a><span style=\"font-weight: 400;\"> to cater to the unique needs of our customers. Our team of proficient Odoo programmers has successfully implemented <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo ERP<\/span><\/a><span style=\"font-weight: 400;\"> solutions for a wide range of businesses, spanning various industries, both within the United States and internationally. Through our extensive experience in executing <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-erp\"><span style=\"font-weight: 400;\">Odoo projects<\/span><\/a><span style=\"font-weight: 400;\">, we have garnered valuable insights and expertise in serving small and medium-sized businesses as well as large corporations.<\/span><\/p><p><span style=\"font-weight: 400;\">We have a team of certified Odoo developers and <\/span><a href=\"https:\/\/www.confianzit.com\/odoo\/consulting-services\"><span style=\"font-weight: 400;\">consultants<\/span><\/a><span style=\"font-weight: 400;\"> who can help you with all your <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-customization\"><span style=\"font-weight: 400;\">Odoo ERP Customization<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/www.confianzit.com\/odoo-implementation\"><span style=\"font-weight: 400;\">Odoo implementation<\/span><\/a><span style=\"font-weight: 400;\"> needs. <\/span><a href=\"https:\/\/www.confianzit.com\/contact-us\"><span style=\"font-weight: 400;\">Call us<\/span><\/a><span style=\"font-weight: 400;\"> today!<\/span><\/p>","_et_gb_content_width":"","footnotes":""},"categories":[143,427],"tags":[304,408,91,172,371],"_links":{"self":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts\/28793"}],"collection":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/comments?post=28793"}],"version-history":[{"count":48,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts\/28793\/revisions"}],"predecessor-version":[{"id":28861,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts\/28793\/revisions\/28861"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/media\/28850"}],"wp:attachment":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/media?parent=28793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/categories?post=28793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/tags?post=28793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}