Solving Troubleshooting Woes with Odoo's ir.logging Module

Overview

by Dharmesh Patel

In Odoo, logging is an essential aspect for developers to track and troubleshoot issues that occur within the system. The ir.logging module in Odoo is responsible for managing logging functionalities.

Developers often face challenges in tracking and resolving issues that arise within the Odoo system. Without a robust logging mechanism like ir.logging, identifying and fixing these issues can be a cumbersome and time-consuming task.

The ir.logging module in Odoo empowers developers with a structured logging approach. By creating records in the Logging Model (ir.logging) and logging messages systematically, developers gain visibility into system operations and can swiftly address issues as they arise.

Logging Process

Here's how logging with ir.logging typically works in Odoo:

Create a record of the Logging Model (ir.logging)

First, you need to define the ir.logging model in your Python code to create a record on it.

def log_xml(self, xml_string, func):
        self.ensure_one()

        if self.debug_logging:
        self.env.flush_all()
        db_name =
self._cr.dbname

# Use a new cursor to avoid rollback that could be caused by an upper method
        try:
                db_registry = registry(db_name)
                with db_registry.cursor() as
cr:
                env = api.Environment(cr, SUPERUSER_ID, {})
                IrLogging = env[
'ir.logging']
                IrLogging.sudo().create({
'name': 'delivery.carrier',
                      'type': 'server',
                      'dbname': db_name,
                      'level': 'DEBUG',
                      'message': xml_string,
                      'path': self.delivery_type,
                      'func': func,
                      'line': 1})
        except psycopg2.
Error:
                pass

Logging Messages

Once you have the logger record, you can see it under the Logging menu. Settings → Technical → Database Structure → Logging

By following this structured logging approach with the ir.logging module, developers can streamline issue tracking and troubleshooting, leading to enhanced system reliability and performance.

Dharmesh Patel 1 May, 2024
Archive
Sign in to leave a comment
How to Override a Controller of a Specific Module in Odoo