This question has been flagged
2 Replies
10958 Views
I have been trying different debugging methods but everything fails.How can i print a variable or msg in log.

i am using tail -f /var/log/openerp/openerp-server.log& for log

my code is 
import logging
from openerp.osv import fields, osv
import time
print "a"*1000

_logger = logging.getLogger(__name__)
class calldata_print_report_wiz(osv.osv_memory):
    _name = "calldata.print.report.wiz"

    def _sel_func(self, cr, uid,context=None):

     print "hello"*100
     obj = self.pool.get('calldata1')
     ids = obj.search(cr, uid, [])
     res = obj.read(cr, uid, ids, ['Caller'], context)
     _logger.debug('Create a %s with vals %s', self._name, res)
     res =[r['Caller'] for r in res]
     return res

    _columns = {
        'date_start': fields.date('Date Start', required=True),
        'date_end': fields.date('Date End', required=True),
#        'Callers':fields.many2one(
 #       'calldata1',

  #   'Callers',
   #     selection=_sel_func
    #    )
       'caller_id':fields.selection(_sel_func, string='Caller'),
   }
    _defaults = {
        'date_start': lambda *a: time.strftime('%Y-%m-%d'),
        'date_end': lambda *a: time.strftime('%Y-%m-%d'),


     }

    def print_report(self, cr, uid, ids, context=None):
      import pdb
      pdb.set_trace()
       import netsvc
       netsvc.Logger().notifyChannel('calldetails1', netsvc.LOG_DEBUG, "Hello")

      if context is None:
            context = {}

      datas = {'ids': context.get('active_ids', [])}
      res = self.read(cr, uid, ids, ['date_start', 'date_end', 'Caller_id'], context=context)
      res = res and res[0] or {}
      datas['form'] = res
      return {
            'type': 'ir.actions.report.xml',
            'report_name':'call',
           }
calldata_print_report_wiz()

Any one please help?

Avatar
Discard
Best Answer

Put the _logging declaration inside the function you want to log and start/stop the server. That will make the log messages start to appear

Also start the server in debug mode or change the logging from .debug to .info

Avatar
Discard
Author

Yes finally it worked thanks alot patently.

Best Answer

There could be several reasons:

  1. Have you restarted the server to apply new print statements?
  2. Be sure you are reading correct log file(perhaps you specified another one when started the server adding -c or config?). If you see current time reading your log the file you are reading is correct.
  3. Why are you launching reading the file as background process? You don't need '&' at the end of command.
  4. Go to Settings --> Configuration --> Database structure --> Objects and check whether there is such a model calldata.print.report.wiz in your database, if not - you forgot to include you file in __init_ section of module. Besides there is no reason to use pdb module in you code as it wouldn't work while you are only reading the file. Cheers.
Avatar
Discard
Author

yes i restarted the server. i restarted server using this command sudo /etc/init.d/openerp restart --debug .there exists calldata.print.report.wiz table in my database.Still why its not showing my print statement result :( ? my configuration file for open erp is /etc/openerp/openerp-server.conf
[options] ; This is the password that allows database operations: ; admin_passwd = admin db_host = False db_port = False db_user = openerp db_password = False

Append following line to conf file: logfile = /var/log/openerp/openerp-server.log and restart the server.

Author

changed configuration and restarted . still no change :(.

Hm, is there any output in console after running tail -f /var/log/openerp/openerp-server.log and accessing server throw web browser?

Author

yes it shows errors if any,login info etc

Ok, let's try the last thing - insert in your code next method: def init(self, cr): print "Hello World"*100 and restart the server. If it will not print - your module is not updating, otherwise try to use 'caller_id' as functional field, not selection.