Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

6

How print a debug message on log file?

By
Bonnet Denis
on 2/12/13, 7:35 AM 11,862 views

I want to print a debug message in a method. I override project.task.work.create method and i don't know if program use my method or the original.In java i print a simple message to see it. How do the same with OpenERP API? I use OpenERP 7 on debian linux.

12

Guewen Baconnier - Software Developer, Camptocamp

--Guewen Baconnier - Software Developer, Camptocamp--
2658
| 6 7 8
Lausanne, Switzerland
--Guewen Baconnier - Software Developer, Camptocamp--

Guewen works at Camptocamp as an Odoo developer since 2010. He is the lead developer of the Odoo Connector framework and the Magento Connector. He is a delegate member of the OCA, a committer and an active contributor to the OCA projects.

 

Guewen Baconnier - Software Developer, Camptocamp
On 2/12/13, 9:33 AM

To display a debug log, you can use the standard python logging module.

Basically, you need to get a logger and you can use it in your methods to output log messages.

Usually, in OpenERP, a _logger is get at the top of the python module, its name being the name of the python module.

import logging
from openerp.osv import orm

_logger = logging.getLogger(__name__)


class project_task_work(orm.Model):
    _inherit = 'project.task.work'

    def create(self, cr, uid, vals, context=None):
        _logger.debug('Create a %s with vals %s', self._name, vals)
        return super(project_task_work, self).create(cr, uid, vals, context=context)

Note that you will need to start your server using the --debug option to show debug logs.

Other options for logging at a higher level (that doesn't require the --debug option) are:


_logger.info('FYI: This is happening')

_logger.warning('WARNING: I don't think you want this to happen!')

_logger.error('ERROR: Something really bad happened!')


It doesn't work(I see nothing on log file but i have a lot of debug info on it). I don't know how debug this personal add-on. I just want to override this method. should I create a new question for this problem?

Bonnet Denis
on 2/12/13, 11:00 AM

If you don't see your logs that's probably because your module is not loaded correctly, or the module's dependencies are wrong. You can create a question focused to the loading of modules with details on your module (people will have to find out why it is not loaded, give them useful information).

Camptocamp SA, Guewen Baconnier - Software Developer, Camptocamp
on 2/12/13, 11:16 AM

thanks a lot

Bonnet Denis
on 2/12/13, 11:26 AM

if it didn't work that's because i hadn't restart openERP. I just restart and it's ok. Thanks again.

Bonnet Denis
on 2/12/13, 12:51 PM

Hi,,,when i am giving _logging.info after _columns in .py file then it is printing to log file but when i am calling to the method then it didn't work?? Please help me out....

Krishna
on 9/25/13, 9:46 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/12/13, 7:35 AM
Seen: 11862 times
Last updated: 10/6/16, 12:47 PM