1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 OpenStack LLC
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
"""Wrapper for built-in logging module."""
19
from __future__ import absolute_import
24
import logging.handlers
29
# A list of things we want to replicate from logging.
31
CRITICAL = logging.CRITICAL
34
WARNING = logging.WARNING
38
NOTSET = logging.NOTSET
42
getLogger = logging.getLogger
45
warning = logging.warning
48
exception = logging.exception
49
critical = logging.critical
54
config = logging.config
55
Formatter = logging.Formatter
58
StreamHandler = logging.StreamHandler
59
WatchedFileHandler = logging.handlers.WatchedFileHandler
60
SysLogHandler = logging.handlers.SysLogHandler
65
def wrapper(*args, **kw):
66
logging.debug('%s(%s, %s) ->', f.func_name, str(args), str(kw))
68
logging.debug(pprint.pformat(rv, indent=2))
74
def fail_gracefully(f):
75
"""Logs exceptions and aborts."""
77
def wrapper(*args, **kw):
80
except Exception as e:
81
# tracebacks are kept in the debug log
82
logging.debug(traceback.format_exc(e))
84
# exception message is printed to all logs