~ubuntu-branches/ubuntu/wily/system-image/wily-proposed

« back to all changes in this revision

Viewing changes to systemimage/logging.py

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Barry Warsaw
  • Date: 2014-09-17 17:56:45 UTC
  • mfrom: (1.2.26)
  • Revision ID: package-import@ubuntu.com-20140917175645-3zt7e1wqtq776s1q
Tags: 2.4-0ubuntu1
[ Barry Warsaw ]
* New upstream release.
  - LP: #1353178 - The channel.ini file can override the device name by
    setting `[service]device`.
  - LP: #1324241 - Add optional instrumentation to collect code coverage
    data during test suite run via tox.
  - LP: #1279970 - When an exception occurs in a `system-image-dbus`
    D-Bus method, signal, or callback, this exception is logged in the
    standard log file, and the process exits.  Also, `[system]loglevel`
    can now take an optional ":level" prefix which can be used to set
    the log level for the D-Bus API methods.  By default, they log at
    `ERROR` level, but can be set lower for debugging purposes.
  - LP: #1365646 - Don't crash when releasing an unacquired checking lock.
  - LP: #1365761 - When checking files for `last_update_date()` ignore
    PermissionErrors and just keep checking the fall backs.
  - LP: #1369714 - `system-image-cli --dbus` has been deprecated and
    will be removed in the future.
* d/control: Remove tox as a build dependency to avoid having to MIR tox,
  virtualenv, and pip.
* d/rules:
  - Call nose2 explicitly to avoid use of tox.
  - Remove unnecessary override_dh_auto_clean rule.
* d/system-image-common.post{inst,rm}: `set -e` to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
            if self.args:
65
65
                msg = msg.format(*self.args)
66
66
            return msg
67
 
        else:
 
67
        else:                                       # pragma: no cover
68
68
            return super().getMessage()
69
69
 
70
70
 
79
79
 
80
80
def initialize(*, verbosity=0):
81
81
    """Initialize the loggers."""
82
 
    level = {
83
 
        0: logging.ERROR,
84
 
        1: logging.INFO,
85
 
        2: logging.DEBUG,
86
 
        3: logging.CRITICAL,
87
 
        }.get(verbosity, logging.ERROR)
88
 
    level = min(level, config.system.loglevel)
89
 
    # Make sure our library's logging uses {}-style messages.
90
 
    logging.setLogRecordFactory(FormattingLogRecord)
91
 
    # Now configure the application level logger based on the ini file.
92
 
    log = logging.getLogger('systemimage')
93
 
    try:
94
 
        handler = _make_handler(Path(config.system.logfile))
95
 
    except PermissionError:
96
 
        handler = _make_handler(
97
 
            Path(xdg_cache_home) / 'system-image' / 'client.log')
98
 
    handler.setLevel(level)
99
 
    formatter = logging.Formatter(style='{', fmt=MSG_FMT, datefmt=DATE_FMT)
100
 
    handler.setFormatter(formatter)
101
 
    log.addHandler(handler)
102
 
    log.propagate = False
103
 
    # If we want more verbosity, add a stream handler.
104
 
    if verbosity == 0:
105
 
        # Set the log level.
106
 
        log.setLevel(level)
107
 
        return
108
 
    handler = logging.StreamHandler(stream=sys.stderr)
109
 
    handler.setLevel(level)
110
 
    handler.setFormatter(formatter)
111
 
    log.addHandler(handler)
112
 
    # Set the overall level on the log object to the minimum level.
113
 
    log.setLevel(level)
 
82
    main, dbus = config.system.loglevel
 
83
    for name, loglevel in (('systemimage', main), ('systemimage.dbus', dbus)):
 
84
        level = {
 
85
            0: logging.ERROR,
 
86
            1: logging.INFO,
 
87
            2: logging.DEBUG,
 
88
            3: logging.CRITICAL,
 
89
            }.get(verbosity, logging.ERROR)
 
90
        level = min(level, loglevel)
 
91
        # Make sure our library's logging uses {}-style messages.
 
92
        logging.setLogRecordFactory(FormattingLogRecord)
 
93
        # Now configure the application level logger based on the ini file.
 
94
        log = logging.getLogger(name)
 
95
        try:
 
96
            handler = _make_handler(Path(config.system.logfile))
 
97
        except PermissionError:
 
98
            handler = _make_handler(
 
99
                Path(xdg_cache_home) / 'system-image' / 'client.log')
 
100
        handler.setLevel(level)
 
101
        formatter = logging.Formatter(style='{', fmt=MSG_FMT, datefmt=DATE_FMT)
 
102
        handler.setFormatter(formatter)
 
103
        log.addHandler(handler)
 
104
        log.propagate = False
 
105
        # If we want more verbosity, add a stream handler.
 
106
        if verbosity == 0:                          # pragma: no branch
 
107
            # Set the log level.
 
108
            log.setLevel(level)
 
109
        else:                                       # pragma: no cover
 
110
            handler = logging.StreamHandler(stream=sys.stderr)
 
111
            handler.setLevel(level)
 
112
            handler.setFormatter(formatter)
 
113
            log.addHandler(handler)
 
114
            # Set the overall level on the log object to the minimum level.
 
115
            log.setLevel(level)
114
116
    # Please be quiet gnupg.
115
117
    gnupg_log = logging.getLogger('gnupg')
116
118
    gnupg_log.propagate = False
117
119
 
118
120
 
119
121
@contextmanager
120
 
def debug_logging():
 
122
def debug_logging(): # pragma: no cover
121
123
    # getEffectiveLevel() is the best we can do, but it's good enough because
122
124
    # we always set the level of the logger.
123
125
    log = logging.getLogger('systemimage')