Enable Dark Mode!
By: Sruthi M

Logging in Odoo 15 ERP

Technical Odoo 15

Logging is a tool that is used in Odoo for analyzing operations that are happening inside the odoo server when running the service.  We can analyze errors or bugs clearly from the logs and we can find the best solutions for this. So logging is an important feature in Odoo for analyzing all the operations happening on our server.
Now we can check how we can add the log messages inside our custom modules.
Import logging
If we are using the logging option in our custom module then first we want to import a module logging from the python standard library. ie,
import logging
_logger = logging.getLogger(__name__)
Here initialized an object _logger by the name of our code file( __name__).
There are different levels for log messages.
_logger.debug is used for debugging.
_logger.warning is used for showing the warnings.
_logger.info is used for showing the information
_logger.error is used for showing the errors.
_logger.critical is used for showing the critical messages.
Then we can describe these levels through an example.
from odoo import api, fields, models, _
import logging
_logger = logging.getLogger(__name__)
class HospitalManagement(models.Model):
    _name = 'hospital.patient'
    _description = 'Patient'
Here we imported logging and also initialized _logger by the name of code and created a new model of hospital management.
def onchange_doctor_id(self):
      _logger.debug("IT IS DEBUG")
      _logger.info("IT IS INFO")
      _logger.error("IT IS Error")
      _logger.warning("IT IS warning")
      _logger.critical("IT IS Critical")
Inside the onchange function of a field, doctor_id add all the log messages. Then check the server log for seeing the log messages.
Here is the server log. hospital_patient is the python file that I added in the log messages and hospital_management  is the corresponding module name. Here in this server log, we can see the whole path for the log.
Other logging options
We can also configure other logging options.
logfile = None // log file for storing the log details. 
log_handler = LEVEL: LEVEL // we can set up the handler at a LEVEL for a given PREFIX.  
For example, if we need to have a WARNING level for the module hospital_management only, then we can run as shown below:
log_level  = info //we can specify the logging level.
log_db_level  = warning // We can specify the Logging database level.
log_db  = False // We can Specify the Logging database.
These are the other options that can be configured in the configuration file.

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message