Search code examples
pythonpython-2.7debuggingloggingodoo

Odoo: How to place debug lines in server code for viewing in /var/log/odoo


I did the following:

  1. Placed some print debug lines in /usr/lib/python2.7/dist-packages/openerp/models.py
  2. Restart the Odoo server via sudo service odoo restart
  3. Login to the Odoo server and perform the actions that will trigger the debug line in step 1.

But my print debug lines aren't appearing in /var/log/odoo/odoo-server.log

Am I missing any steps above? How to debug Python code in Odoo in general? Thanks!


Solution

  • 1- In your python file you can define a _logger

    import logging
    _logger = logging.getLogger(__name__)
    
    class MyClass(models.Model):
    
        # [...]
    
        _logger.debug("Debug message")
    

    Modify this attribute in your configuration file

    log_level = debug
    

    Restart the service, and the message will be printed in your log file:

    2015-08-23 17:32:05,401 2249 DEBUG ? openerp.service.server: Debug message
    

    2 - You can use pudb to set a breakpoint like following:

    class MyClass(models.Model):
    
        # [...]
    
        import pudb;pu.db # This will create a breakpoint