~ceilometer-drivers/ceilometer/trunk

« back to all changes in this revision

Viewing changes to ceilometer/openstack/common/log.py

  • Committer: Angus Salkeld
  • Date: 2012-11-03 00:31:11 UTC
  • Revision ID: git-v1:4c43441d9dafedbc1b73cf8abdec32b1ccb65a71
Update common (except policy)

Change-Id: I17a89a15ff3af5b9f31bf14b1bbe29b024cfc8c1

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
    cfg.BoolOpt('publish_errors',
77
77
                default=False,
78
78
                help='publish error events'),
 
79
    cfg.BoolOpt('fatal_deprecations',
 
80
                default=False,
 
81
                help='make deprecations fatal'),
79
82
 
80
83
    # NOTE(mikal): there are two options here because sometimes we are handed
81
84
    # a full instance (and could include more information), and other times we
170
173
    def audit(self, msg, *args, **kwargs):
171
174
        self.log(logging.AUDIT, msg, *args, **kwargs)
172
175
 
 
176
    def deprecated(self, msg, *args, **kwargs):
 
177
        stdmsg = _("Deprecated Config: %s") % msg
 
178
        if CONF.fatal_deprecations:
 
179
            self.critical(stdmsg, *args, **kwargs)
 
180
            raise DeprecatedConfig(msg=stdmsg)
 
181
        else:
 
182
            self.warn(stdmsg, *args, **kwargs)
 
183
 
173
184
    def process(self, msg, kwargs):
174
185
        if 'extra' not in kwargs:
175
186
            kwargs['extra'] = {}
450
461
    def format(self, record):
451
462
        record.color = self.LEVEL_COLORS[record.levelno]
452
463
        return logging.StreamHandler.format(self, record)
 
464
 
 
465
 
 
466
class DeprecatedConfig(Exception):
 
467
    message = _("Fatal call to deprecated config: %(msg)s")
 
468
 
 
469
    def __init__(self, msg):
 
470
        super(Exception, self).__init__(self.message % dict(msg=msg))