~ubuntu-branches/ubuntu/saucy/keystone/saucy

« back to all changes in this revision

Viewing changes to keystone/common/logging.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page, Adam Gandelman
  • Date: 2013-09-09 18:02:41 UTC
  • mfrom: (1.1.36)
  • Revision ID: package-import@ubuntu.com-20130909180241-5pizm6rcauhg4x93
Tags: 1:2013.2~b3-0ubuntu1
[ Chuck Short ]
* New upstream release. 
* debian/control: Add python-oslo.sphinx as a build dependency.
* debian/control: Add python-babel as a build dependency.
* debian/control: Add python-dogpile.cache as a build dependency.
* debian/control: Add python-oauth2 as a build dependency. 
* debian/patches/sql_connection.patch: Refreshed

[ James Page ]
* d/patches/fix-ubuntu-tests.patch: Fixup for new tests location.
* d/patches/ubuntu-test-overrides.patch: Override testing defaults
  using patches.
* d/rules: Rework for patching approach for test_overrides.conf.
* d/tests/test_overrides.conf: Dropped - no longer required.
* d/control: Add python-netaddr to BD's.

[ Adam Gandelman ]
* debian/control: Add python-testtools to Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2012 OpenStack LLC
4
 
#
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
8
 
#
9
 
#      http://www.apache.org/licenses/LICENSE-2.0
10
 
#
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
15
 
# under the License.
16
 
 
17
 
"""Wrapper for built-in logging module."""
18
 
 
19
 
from __future__ import absolute_import
20
 
 
21
 
import functools
22
 
import logging
23
 
import logging.config
24
 
import logging.handlers
25
 
import pprint
26
 
import traceback
27
 
 
28
 
 
29
 
# A list of things we want to replicate from logging.
30
 
# levels
31
 
CRITICAL = logging.CRITICAL
32
 
FATAL = logging.FATAL
33
 
ERROR = logging.ERROR
34
 
WARNING = logging.WARNING
35
 
WARN = logging.WARN
36
 
INFO = logging.INFO
37
 
DEBUG = logging.DEBUG
38
 
NOTSET = logging.NOTSET
39
 
 
40
 
 
41
 
# methods
42
 
getLogger = logging.getLogger
43
 
debug = logging.debug
44
 
info = logging.info
45
 
warning = logging.warning
46
 
warn = logging.warn
47
 
error = logging.error
48
 
exception = logging.exception
49
 
critical = logging.critical
50
 
log = logging.log
51
 
 
52
 
# classes
53
 
root = logging.root
54
 
config = logging.config
55
 
Formatter = logging.Formatter
56
 
 
57
 
# handlers
58
 
StreamHandler = logging.StreamHandler
59
 
WatchedFileHandler = logging.handlers.WatchedFileHandler
60
 
SysLogHandler = logging.handlers.SysLogHandler
61
 
 
62
 
 
63
 
def log_debug(f):
64
 
    @functools.wraps(f)
65
 
    def wrapper(*args, **kw):
66
 
        logging.debug('%s(%s, %s) ->', f.func_name, str(args), str(kw))
67
 
        rv = f(*args, **kw)
68
 
        logging.debug(pprint.pformat(rv, indent=2))
69
 
        logging.debug('')
70
 
        return rv
71
 
    return wrapper
72
 
 
73
 
 
74
 
def fail_gracefully(f):
75
 
    """Logs exceptions and aborts."""
76
 
    @functools.wraps(f)
77
 
    def wrapper(*args, **kw):
78
 
        try:
79
 
            return f(*args, **kw)
80
 
        except Exception as e:
81
 
            # tracebacks are kept in the debug log
82
 
            logging.debug(traceback.format_exc(e))
83
 
 
84
 
            # exception message is printed to all logs
85
 
            logging.critical(e)
86
 
 
87
 
            exit(1)
88
 
    return wrapper