[IMP] openerp.addons.base: _logger with fully qualified module name.

bzr revid: vmt@openerp.com-20120124114730-24m0ftu1wbowg8a0
This commit is contained in:
Vo Minh Thu 2012-01-24 12:47:30 +01:00
parent eadcdd1fd6
commit f5db1d10ec
7 changed files with 34 additions and 33 deletions

View File

@ -36,6 +36,8 @@ from tools.safe_eval import safe_eval as eval
from tools.translate import _
from socket import gethostname
_logger = logging.getLogger(__name__)
class actions(osv.osv):
_name = 'ir.actions.actions'
_table = 'ir_actions'
@ -550,7 +552,6 @@ class actions_server(osv.osv):
}
def get_email(self, cr, uid, action, context):
logger = logging.getLogger('Workflow')
obj_pool = self.pool.get(action.model_id.model)
id = context.get('active_id')
obj = obj_pool.browse(cr, uid, id)
@ -566,12 +567,11 @@ class actions_server(osv.osv):
try:
obj = getattr(obj, field)
except Exception:
logger.exception('Failed to parse: %s', field)
_logger.exception('Failed to parse: %s', field)
return obj
def get_mobile(self, cr, uid, action, context):
logger = logging.getLogger('Workflow')
obj_pool = self.pool.get(action.model_id.model)
id = context.get('active_id')
obj = obj_pool.browse(cr, uid, id)
@ -587,7 +587,7 @@ class actions_server(osv.osv):
try:
obj = getattr(obj, field)
except Exception:
logger.exception('Failed to parse: %s', field)
_logger.exception('Failed to parse: %s', field)
return obj
@ -624,7 +624,6 @@ class actions_server(osv.osv):
# FIXME: refactor all the eval() calls in run()!
def run(self, cr, uid, ids, context=None):
logger = logging.getLogger(self._name)
if context is None:
context = {}
user = self.pool.get('res.users').browse(cr, uid, uid)
@ -668,11 +667,11 @@ class actions_server(osv.osv):
pass
if not address:
logger.info('No partner email address specified, not sending any email.')
_logger.info('No partner email address specified, not sending any email.')
continue
if not email_from:
logger.debug('--email-from command line option is not specified, using a fallback value instead.')
_logger.debug('--email-from command line option is not specified, using a fallback value instead.')
if user.user_email:
email_from = user.user_email
else:
@ -685,9 +684,9 @@ class actions_server(osv.osv):
msg = ir_mail_server.build_email(email_from, [address], subject, body)
res_email = ir_mail_server.send_email(cr, uid, msg)
if res_email:
logger.info('Email successfully sent to: %s', address)
_logger.info('Email successfully sent to: %s', address)
else:
logger.warning('Failed to send email to: %s', address)
_logger.warning('Failed to send email to: %s', address)
if action.state == 'trigger':
wf_service = netsvc.LocalService("workflow")
@ -701,7 +700,7 @@ class actions_server(osv.osv):
#TODO: set the user and password from the system
# for the sms gateway user / password
# USE smsclient module from extra-addons
logger.warning('SMS Facility has not been implemented yet. Use smsclient module!')
_logger.warning('SMS Facility has not been implemented yet. Use smsclient module!')
if action.state == 'other':
res = []

View File

@ -37,6 +37,8 @@ from tools import DEFAULT_SERVER_DATETIME_FORMAT
from tools.safe_eval import safe_eval as eval
from tools.translate import _
_logger = logging.getLogger(__name__)
def str2tuple(s):
return eval('tuple(%s)' % (s or ''))
@ -87,8 +89,6 @@ class ir_cron(osv.osv):
'doall' : lambda *a: 1
}
_logger = logging.getLogger('cron')
def _check_args(self, cr, uid, ids, context=None):
try:
for this in self.browse(cr, uid, ids, context):
@ -114,7 +114,7 @@ class ir_cron(osv.osv):
"""
cr.rollback()
self._logger.exception("Call of self.pool.get('%s').%s(cr, uid, *%r) failed in Job %s" % (model_name, method_name, args, job_id))
_logger.exception("Call of self.pool.get('%s').%s(cr, uid, *%r) failed in Job %s" % (model_name, method_name, args, job_id))
def _callback(self, cr, uid, model_name, method_name, args, job_id):
""" Run the method associated to a given job
@ -132,14 +132,13 @@ class ir_cron(osv.osv):
method = getattr(model, method_name)
try:
netsvc.log('cron', (cr.dbname,uid,'*',model_name,method_name)+tuple(args), channel=logging.DEBUG,
depth=(None if self._logger.isEnabledFor(logging.DEBUG_RPC_ANSWER) else 1), fn='object.execute')
logger = logging.getLogger('execution time')
if logger.isEnabledFor(logging.DEBUG):
depth=(None if _logger.isEnabledFor(logging.DEBUG_RPC_ANSWER) else 1), fn='object.execute')
if _logger.isEnabledFor(logging.DEBUG):
start_time = time.time()
method(cr, uid, *args)
if logger.isEnabledFor(logging.DEBUG):
if _logger.isEnabledFor(logging.DEBUG):
end_time = time.time()
logger.log(logging.DEBUG, '%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name))
_logger.log(logging.DEBUG, '%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name))
except Exception, e:
self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e)
@ -224,7 +223,7 @@ class ir_cron(osv.osv):
except psycopg2.OperationalError, e:
if e.pgcode == '55P03':
# Class 55: Object not in prerequisite state; 55P03: lock_not_available
self._logger.debug('Another process/thread is already busy executing job `%s`, skipping it.', job['name'])
_logger.debug('Another process/thread is already busy executing job `%s`, skipping it.', job['name'])
continue
else:
# Unexpected OperationalError
@ -240,7 +239,7 @@ class ir_cron(osv.osv):
task_thread.setDaemon(False)
openerp.cron.take_thread_slot()
task_thread.start()
self._logger.debug('Cron execution thread for job `%s` spawned', job['name'])
_logger.debug('Cron execution thread for job `%s` spawned', job['name'])
# Find next earliest job ignoring currently processed jobs (by this and other cron threads)
find_next_time_query = """SELECT min(nextcall) AS min_next_call
@ -261,7 +260,7 @@ class ir_cron(osv.osv):
openerp.cron.schedule_wakeup(next_call, db_name)
except Exception, ex:
self._logger.warning('Exception in cron:', exc_info=True)
_logger.warning('Exception in cron:', exc_info=True)
finally:
cr.commit()

View File

@ -40,7 +40,7 @@ import openerp.tools as tools
# it is moved to loglevels until we refactor tools.
from openerp.loglevels import ustr
_logger = logging.getLogger('ir.mail_server')
_logger = logging.getLogger(__name__)
class MailDeliveryException(osv.except_osv):
"""Specific exception subclass for mail delivery errors"""

View File

@ -32,6 +32,8 @@ from tools import config
from tools.translate import _
import pooler
_logger = logging.getLogger(__name__)
def _get_fields_type(self, cr, uid, context=None):
return sorted([(k,k) for k,v in fields.__dict__.iteritems()
if type(v) == types.TypeType
@ -232,7 +234,7 @@ class ir_model_fields(osv.osv):
try:
selection_list = eval(selection)
except Exception:
logging.getLogger('ir.model').warning('Invalid selection list definition for fields.selection', exc_info=True)
_logger.warning('Invalid selection list definition for fields.selection', exc_info=True)
raise except_orm(_('Error'),
_("The Selection Options expression is not a valid Pythonic expression." \
"Please provide an expression in the [('key','Label'), ...] format."))
@ -588,7 +590,6 @@ class ir_model_data(osv.osv):
update them seamlessly.
"""
_name = 'ir.model.data'
__logger = logging.getLogger('addons.base.'+_name)
_order = 'module,model,name'
_columns = {
'name': fields.char('External Identifier', required=True, size=128, select=1,
@ -821,13 +822,13 @@ class ir_model_data(osv.osv):
if not config.get('import_partial'):
for (model, res_id) in to_unlink:
if self.pool.get(model):
self.__logger.info('Deleting %s@%s', res_id, model)
_logger.info('Deleting %s@%s', res_id, model)
try:
self.pool.get(model).unlink(cr, uid, [res_id])
cr.commit()
except Exception:
cr.rollback()
self.__logger.warn(
_logger.warn(
'Could not delete obsolete record with id: %d of model %s\n'
'There should be some relation that points to this resource\n'
'You should manually fix this and restart with --update=module',

View File

@ -24,7 +24,7 @@ import time
import openerp
_logger = logging.getLogger('ir_sequence')
_logger = logging.getLogger(__name__)
class ir_sequence_type(openerp.osv.osv.osv):
_name = 'ir.sequence.type'

View File

@ -23,6 +23,8 @@ from osv import fields, osv
import tools
import logging
_logger = logging.getLogger(__name__)
TRANSLATION_TYPE = [
('field', 'Field'),
('model', 'Object'),
@ -87,13 +89,12 @@ class ir_translation_import_cursor(object):
def finish(self):
""" Transfer the data from the temp table to ir.translation
"""
logger = logging.getLogger('orm')
cr = self._cr
if self._debug:
cr.execute("SELECT count(*) FROM %s" % self._table_name)
c = cr.fetchone()[0]
logger.debug("ir.translation.cursor: We have %d entries to process", c)
_logger.debug("ir.translation.cursor: We have %d entries to process", c)
# Step 1: resolve ir.model.data references to res_ids
cr.execute("""UPDATE %s AS ti
@ -109,7 +110,7 @@ class ir_translation_import_cursor(object):
cr.execute("SELECT imd_module, imd_model, imd_name FROM %s " \
"WHERE res_id IS NULL AND imd_module IS NOT NULL" % self._table_name)
for row in cr.fetchall():
logger.debug("ir.translation.cursor: missing res_id for %s. %s/%s ", *row)
_logger.debug("ir.translation.cursor: missing res_id for %s. %s/%s ", *row)
cr.execute("DELETE FROM %s WHERE res_id IS NULL AND imd_module IS NOT NULL" % \
self._table_name)
@ -143,7 +144,7 @@ class ir_translation_import_cursor(object):
cr.execute('SELECT COUNT(*) FROM ONLY %s AS irt, %s AS ti WHERE %s' % \
(self._parent_table, self._table_name, find_expr))
c = cr.fetchone()[0]
logger.debug("ir.translation.cursor: %d entries now in ir.translation, %d common entries with tmp", c1, c)
_logger.debug("ir.translation.cursor: %d entries now in ir.translation, %d common entries with tmp", c1, c)
# Step 4: cleanup
cr.execute("DROP TABLE %s" % self._table_name)

View File

@ -27,6 +27,8 @@ import tools
import os
import logging
_logger = logging.getLogger(__name__)
class view_custom(osv.osv):
_name = 'ir.ui.view.custom'
_order = 'create_date desc' # search(limit=1) should return the last customization
@ -72,7 +74,6 @@ class view(osv.osv):
_order = "priority,name"
def _check_xml(self, cr, uid, ids, context=None):
logger = logging.getLogger('init')
for view in self.browse(cr, uid, ids, context):
eview = etree.fromstring(view.arch.encode('utf8'))
frng = tools.file_open(os.path.join('base','rng','view.rng'))
@ -81,7 +82,7 @@ class view(osv.osv):
relaxng = etree.RelaxNG(relaxng_doc)
if not relaxng.validate(eview):
for error in relaxng.error_log:
logger.error(tools.ustr(error))
_logger.error(tools.ustr(error))
return False
finally:
frng.close()