~ubuntu-managed-branches/ubuntu-system-image/system-image

« back to all changes in this revision

Viewing changes to systemimage/logging.py

  • Committer: CI Train Bot
  • Date: 2015-09-28 21:37:42 UTC
  • mfrom: (243.1.2 citrain302)
  • Revision ID: ci-train-bot@canonical.com-20150928213742-p2r2eqlnh6d3d7wl
* New upstream release.
  - LP: #1495688 - Don't crash when one of the .ini files is a dangling
    symlink.
  - d/rules: override_dh_auto_clean because otherwise, pybuild will
    remove the .egg-info files and that causes the Jenkins job in the CI
    train to fail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
__all__ = [
19
19
    'debug_logging',
20
20
    'initialize',
 
21
    'make_handler',
21
22
    ]
22
23
 
23
24
 
68
69
            return super().getMessage()
69
70
 
70
71
 
71
 
def _make_handler(path):
 
72
def make_handler(path):
72
73
    # issue21539 - mkdir(..., exist_ok=True)
73
74
    with suppress(FileExistsError):
74
75
        path.parent.mkdir(DEFAULT_DIRMODE, parents=True)
75
76
    path.touch(LOGFILE_PERMISSIONS)
76
77
    # Our handler will output in UTF-8 using {} style logging.
77
 
    return logging.FileHandler(bytes(path), encoding='utf-8')
 
78
    formatter = logging.Formatter(style='{', fmt=MSG_FMT, datefmt=DATE_FMT)
 
79
    handler = logging.FileHandler(bytes(path), encoding='utf-8')
 
80
    handler.setFormatter(formatter)
 
81
    return handler
78
82
 
79
83
 
80
84
def initialize(*, verbosity=0):
95
99
        # Now configure the application level logger based on the ini file.
96
100
        log = logging.getLogger(name)
97
101
        try:
98
 
            handler = _make_handler(Path(config.system.logfile))
 
102
            handler = make_handler(Path(config.system.logfile))
99
103
        except PermissionError:
100
 
            handler = _make_handler(
 
104
            handler = make_handler(
101
105
                Path(xdg_cache_home) / 'system-image' / 'client.log')
102
106
        handler.setLevel(level)
103
 
        formatter = logging.Formatter(style='{', fmt=MSG_FMT, datefmt=DATE_FMT)
104
 
        handler.setFormatter(formatter)
105
107
        log.addHandler(handler)
106
108
        log.propagate = False
107
109
        # If we want more verbosity, add a stream handler.
111
113
        else:                                       # pragma: no cover
112
114
            handler = logging.StreamHandler(stream=sys.stderr)
113
115
            handler.setLevel(level)
 
116
            formatter = logging.Formatter(
 
117
                style='{', fmt=MSG_FMT, datefmt=DATE_FMT)
114
118
            handler.setFormatter(formatter)
115
119
            log.addHandler(handler)
116
120
            # Set the overall level on the log object to the minimum level.