[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 logging
import warnings
LOG_NOTSET = 'notset'
LOG_DEBUG_SQL = 'debug_sql'
@ -44,20 +43,22 @@ logging.addLevelName(logging.DEBUG_SQL, 'DEBUG_SQL')
logging.TEST = logging.INFO - 5
logging.addLevelName(logging.TEST, 'TEST')
_logger = logging.getLogger(__name__)
class Logger(object):
def __init__(self):
warnings.warn("The netsvc.Logger API shouldn't be used anymore, please "
"use the standard `logging.getLogger` API instead",
PendingDeprecationWarning, stacklevel=2)
_logger.warning(
"The netsvc.Logger API shouldn't be used anymore, please "
"use the standard `logging.getLogger` API instead.")
super(Logger, self).__init__()
def notifyChannel(self, name, level, msg):
warnings.warn("notifyChannel API shouldn't be used anymore, please use "
"the standard `logging` module instead",
PendingDeprecationWarning, stacklevel=2)
_logger.warning(
"notifyChannel API shouldn't be used anymore, please use "
"the standard `logging` module instead.")
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):
fct = lambda msg, *args, **kwargs: log.log(getattr(logging, level.upper()), msg, *args, **kwargs)

View File

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

View File

@ -52,7 +52,6 @@ import re
import simplejson
import time
import types
import warnings
from lxml import etree
import fields
@ -4745,8 +4744,8 @@ class BaseModel(object):
return [x[0] for x in cr.fetchall()]
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!" % \
self._name, DeprecationWarning, stacklevel=3)
_logger.warning("You are using deprecated %s.check_recursion(). Please use the '_check_recursion()' instead!" % \
self._name)
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"
return self._check_recursion(cr, uid, ids, context, parent)

View File

@ -50,7 +50,6 @@ except ImportError:
import filters
import utils
import warnings
from generic import *
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.psycopg1 import cursor as psycopg1cursor
from threading import currentThread
import warnings
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
@ -471,8 +470,7 @@ class Connection(object):
def __nonzero__(self):
"""Check if connection is possible"""
try:
warnings.warn("You use an expensive function to test a connection.",
DeprecationWarning, stacklevel=1)
_logger.warning("__nonzero__() is deprecated. (It is too expensive to test a connection.)")
cr = self.cursor()
cr.close()
return True

View File

@ -37,7 +37,6 @@ import socket
import sys
import threading
import time
import warnings
import zipfile
from collections import defaultdict
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.orm import except_orm
import sys
import warnings
_logger = logging.getLogger(__name__)
@ -51,7 +50,7 @@ class interface(netsvc.Service):
def __init__(self, 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"
"It must use the openerp.osv.TransientModel class instead." % \
name, DeprecationWarning, stacklevel=3)