Logging in odoo is very important thing in order to know what is happening in odoo server and to tracking any process in the server , and to make logging in odoo we have 2 steps
- Import logging in odoo class just like
_logger = logging.getLogger(__name__)
- use type of logging in odoo which has many types just as
INFO Logging : to log info message
_logger.info("Any thing you want to log it")
WARNING Logging : to log WARNING message
_logger.warring("Any thing you want to log it")
DEBUG Logging : to log DEBUG message
_logger.debug("Any thing you want to log it")
ERROR Logging : to log ERROR message
_logger.error("Any thing you want to log it")
CRITICAL Logging : to log CRITICAL message
_logger.critical("Any thing you want to log it")
Now let us Give an example and say that we want to log the current company name and the current user name , so
we will inherit res.company name and add our logger in it as bellow
class LoggerLogger(models.Model):
_inherit = 'res.company'
def odoo_logger(self,current_company,current_user):
"""
Function To make logging for company and uers
"""
_logger.info("Current Company : "+current_company+", The Current User : "+current_user)
and when we call this function we have to pass company and user such as
def logger_caller(self):
current_company = self.env.user.company_id.name
current_user = self.env.user.name
self.env.user.company_id.odoo_logger(current_company,current_user)
Note :
to know how to put file name , function name and calling line in the logging file from here
No comments:
Post a Comment