11 odoo
vlab edited this page 4 years ago

Development hacks

Dev features in compose.yml

- "--dev <feature,feature,...,feature>"

List of features:

  • all: all the features below are activated
  • xml: read template qweb from xml file directly instead of database. Once a template has been modified in database, it will be not be read from the xml file until the next update/init.
  • reload: restart server when python file are updated (may not be detected depending on the text editor used)
  • qweb: break in the evaluation of qweb template when a node contains t-debug='debugger'
  • (i)p(u)db: start the chosen python debugger in the code when an unexpected error is raised before logging and returning the error.

Troubleshooting

Use Debug mode

Here are the several steps to activate the Debug mode when you develop a Odoo module:

  1. Add the following line in the compose.yml:
- "--log-level=debug"
  1. Add the following code in your Python file :
import logging  #At the beginning of your file


_logger = logging.getLogger(__name__)   #Before the class where you want to add logs

# To add in you code, where you want to display some messages in the logs
_logger.debug("Create a %s with vals %s", self._name, vals)         # To display a DEBUG message
_logger.info("FYI: This is happening")                              # To display an INFO message
_logger.warning("WARNING: I don't think you want this to happen!")  # To display a WARNING message
_logger.error("ERROR: Something really bad happened!")              # To display an ERROR message

Then consult the logs.

Getting logs

There are 2 ways to get Odoo logs :

Via compose command

To get logs in-live: compose logs odoo -f

To get the last logs: compose logs odoo --tail=200

Via logs files

In production (not in dev environment), you can consult the logs in the file odoo.log in the repository /srv/datastore/data/odoo/var/log/odoo