[IMP] warnings: turn warnings.warn into logging.warning:

Warnings are handled with the other logs (and not always sent to stderr),
they also appear under a module __name__ channel instead of py.warn.
The disadvantage is that there is no longer specific warnings,
such as pending deprecation warning or deprecation warning.

bzr revid: vmt@openerp.com-20120125132407-u33idc0qh7ecs1i5
This commit is contained in:
Vo Minh Thu 2012-01-25 14:24:07 +01:00
parent 97b75ce3f5
commit 283304f9a2
7 changed files with 36 additions and 30 deletions

View File

@ -21,7 +21,6 @@
import sys import sys
import logging import logging
import warnings
LOG_NOTSET = 'notset' LOG_NOTSET = 'notset'
LOG_DEBUG_SQL = 'debug_sql' LOG_DEBUG_SQL = 'debug_sql'
@ -44,20 +43,22 @@ logging.addLevelName(logging.DEBUG_SQL, 'DEBUG_SQL')
logging.TEST = logging.INFO - 5 logging.TEST = logging.INFO - 5
logging.addLevelName(logging.TEST, 'TEST') logging.addLevelName(logging.TEST, 'TEST')
_logger = logging.getLogger(__name__)
class Logger(object): class Logger(object):
def __init__(self): def __init__(self):
warnings.warn("The netsvc.Logger API shouldn't be used anymore, please " _logger.warning(
"use the standard `logging.getLogger` API instead", "The netsvc.Logger API shouldn't be used anymore, please "
PendingDeprecationWarning, stacklevel=2) "use the standard `logging.getLogger` API instead.")
super(Logger, self).__init__() super(Logger, self).__init__()
def notifyChannel(self, name, level, msg): def notifyChannel(self, name, level, msg):
warnings.warn("notifyChannel API shouldn't be used anymore, please use " _logger.warning(
"the standard `logging` module instead", "notifyChannel API shouldn't be used anymore, please use "
PendingDeprecationWarning, stacklevel=2) "the standard `logging` module instead.")
from service.web_services import common from service.web_services import common
log = logging.getLogger(ustr(name)) log = logging.getLogger(__name__ + '(deprecated channel: ' + ustr(name) + ')')
if level in [LOG_DEBUG_RPC, LOG_TEST] and not hasattr(log, level): if level in [LOG_DEBUG_RPC, LOG_TEST] and not hasattr(log, level):
fct = lambda msg, *args, **kwargs: log.log(getattr(logging, level.upper()), msg, *args, **kwargs) fct = lambda msg, *args, **kwargs: log.log(getattr(logging, level.upper()), msg, *args, **kwargs)

View File

@ -34,10 +34,10 @@
import base64 import base64
import datetime as DT import datetime as DT
import logging
import re import re
import string import string
import sys import sys
import warnings
import xmlrpclib import xmlrpclib
from psycopg2 import Binary from psycopg2 import Binary
@ -48,6 +48,8 @@ from openerp.tools.translate import _
from openerp.tools import float_round, float_repr from openerp.tools import float_round, float_repr
import simplejson import simplejson
_logger = logging.getLogger(__name__)
def _symbol_set(symb): def _symbol_set(symb):
if symb == None or symb == False: if symb == None or symb == False:
return None return None
@ -139,8 +141,10 @@ class boolean(_column):
def __init__(self, string='unknown', required=False, **args): def __init__(self, string='unknown', required=False, **args):
super(boolean, self).__init__(string=string, required=required, **args) super(boolean, self).__init__(string=string, required=required, **args)
if required: if required:
warnings.warn("Making a boolean field `required` has no effect, as NULL values are " _logger.warning(
"automatically turned into False", PendingDeprecationWarning, stacklevel=2) "required=True is deprecated: making a boolean field"
" `required` has no effect, as NULL values are "
"automatically turned into False.")
class integer(_column): class integer(_column):
_type = 'integer' _type = 'integer'
@ -152,8 +156,10 @@ class integer(_column):
def __init__(self, string='unknown', required=False, **args): def __init__(self, string='unknown', required=False, **args):
super(integer, self).__init__(string=string, required=required, **args) super(integer, self).__init__(string=string, required=required, **args)
if required: if required:
warnings.warn("Making an integer field `required` has no effect, as NULL values are " _logger.warning(
"automatically turned into 0", PendingDeprecationWarning, stacklevel=2) "required=True is deprecated: making an integer field"
" `required` has no effect, as NULL values are "
"automatically turned into 0.")
class integer_big(_column): class integer_big(_column):
"""Experimental 64 bit integer column type, currently unused. """Experimental 64 bit integer column type, currently unused.
@ -176,8 +182,10 @@ class integer_big(_column):
def __init__(self, string='unknown', required=False, **args): def __init__(self, string='unknown', required=False, **args):
super(integer_big, self).__init__(string=string, required=required, **args) super(integer_big, self).__init__(string=string, required=required, **args)
if required: if required:
warnings.warn("Making an integer_big field `required` has no effect, as NULL values are " _logger.warning(
"automatically turned into 0", PendingDeprecationWarning, stacklevel=2) "required=True is deprecated: making an integer_big field"
" `required` has no effect, as NULL values are "
"automatically turned into 0.")
class reference(_column): class reference(_column):
_type = 'reference' _type = 'reference'
@ -238,8 +246,10 @@ class float(_column):
# synopsis: digits_compute(cr) -> (precision, scale) # synopsis: digits_compute(cr) -> (precision, scale)
self.digits_compute = digits_compute self.digits_compute = digits_compute
if required: if required:
warnings.warn("Making a float field `required` has no effect, as NULL values are " _logger.warning(
"automatically turned into 0.0", PendingDeprecationWarning, stacklevel=2) "required=True is deprecated: making a float field"
" `required` has no effect, as NULL values are "
"automatically turned into 0.0.")
def digits_change(self, cr): def digits_change(self, cr):
if self.digits_compute: if self.digits_compute:
@ -355,7 +365,7 @@ class one2one(_column):
_deprecated = True _deprecated = True
def __init__(self, obj, string='unknown', **args): def __init__(self, obj, string='unknown', **args):
warnings.warn("The one2one field doesn't work anymore", DeprecationWarning) _logger.warning("The one2one field is deprecated and doesn't work anymore.")
_column.__init__(self, string=string, **args) _column.__init__(self, string=string, **args)
self._obj = obj self._obj = obj
@ -620,8 +630,9 @@ class many2many(_column):
for id in ids: for id in ids:
res[id] = [] res[id] = []
if offset: if offset:
warnings.warn("Specifying offset at a many2many.get() may produce unpredictable results.", _logger.warning(
DeprecationWarning, stacklevel=2) "Specifying offset at a many2many.get() is deprecated and may"
" produce unpredictable results.")
obj = model.pool.get(self._obj) obj = model.pool.get(self._obj)
rel, id1, id2 = self._sql_names(model) rel, id1, id2 = self._sql_names(model)

View File

@ -52,7 +52,6 @@ import re
import simplejson import simplejson
import time import time
import types import types
import warnings
from lxml import etree from lxml import etree
import fields import fields
@ -4745,8 +4744,8 @@ class BaseModel(object):
return [x[0] for x in cr.fetchall()] return [x[0] for x in cr.fetchall()]
def check_recursion(self, cr, uid, ids, context=None, parent=None): def check_recursion(self, cr, uid, ids, context=None, parent=None):
warnings.warn("You are using deprecated %s.check_recursion(). Please use the '_check_recursion()' instead!" % \ _logger.warning("You are using deprecated %s.check_recursion(). Please use the '_check_recursion()' instead!" % \
self._name, DeprecationWarning, stacklevel=3) self._name)
assert parent is None or parent in self._columns or parent in self._inherit_fields,\ assert parent is None or parent in self._columns or parent in self._inherit_fields,\
"The 'parent' parameter passed to check_recursion() must be None or a valid field name" "The 'parent' parameter passed to check_recursion() must be None or a valid field name"
return self._check_recursion(cr, uid, ids, context, parent) return self._check_recursion(cr, uid, ids, context, parent)

View File

@ -50,7 +50,6 @@ except ImportError:
import filters import filters
import utils import utils
import warnings
from generic import * from generic import *
from utils import readNonWhitespace, readUntilWhitespace, ConvertFunctionsToVirtualList from utils import readNonWhitespace, readUntilWhitespace, ConvertFunctionsToVirtualList

View File

@ -42,7 +42,6 @@ from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ
from psycopg2.pool import PoolError from psycopg2.pool import PoolError
from psycopg2.psycopg1 import cursor as psycopg1cursor from psycopg2.psycopg1 import cursor as psycopg1cursor
from threading import currentThread from threading import currentThread
import warnings
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
@ -471,8 +470,7 @@ class Connection(object):
def __nonzero__(self): def __nonzero__(self):
"""Check if connection is possible""" """Check if connection is possible"""
try: try:
warnings.warn("You use an expensive function to test a connection.", _logger.warning("__nonzero__() is deprecated. (It is too expensive to test a connection.)")
DeprecationWarning, stacklevel=1)
cr = self.cursor() cr = self.cursor()
cr.close() cr.close()
return True return True

View File

@ -37,7 +37,6 @@ import socket
import sys import sys
import threading import threading
import time import time
import warnings
import zipfile import zipfile
from collections import defaultdict from collections import defaultdict
from datetime import datetime from datetime import datetime

View File

@ -32,7 +32,6 @@ import openerp.pooler as pooler
from openerp.osv.osv import except_osv from openerp.osv.osv import except_osv
from openerp.osv.orm import except_orm from openerp.osv.orm import except_orm
import sys import sys
import warnings
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -51,7 +50,7 @@ class interface(netsvc.Service):
def __init__(self, name): def __init__(self, name):
assert not self.exists('wizard.'+name), 'The wizard "%s" already exists!' % (name,) assert not self.exists('wizard.'+name), 'The wizard "%s" already exists!' % (name,)
warnings.warn( _logger.warning(
"The wizard %s uses the deprecated openerp.wizard.interface class.\n" "The wizard %s uses the deprecated openerp.wizard.interface class.\n"
"It must use the openerp.osv.TransientModel class instead." % \ "It must use the openerp.osv.TransientModel class instead." % \
name, DeprecationWarning, stacklevel=3) name, DeprecationWarning, stacklevel=3)