/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/trace.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
form.
46
46
"""
47
47
 
48
 
from __future__ import absolute_import
49
 
 
50
48
# FIXME: Unfortunately it turns out that python's logging module
51
49
# is quite expensive, even when the message is not printed by any handlers.
52
50
# We should perhaps change back to just simply doing it here.
57
55
# that.
58
56
 
59
57
import errno
 
58
from io import StringIO
60
59
import logging
61
60
import os
62
61
import sys
82
81
    errors,
83
82
    )
84
83
 
85
 
from .sixish import (
86
 
    PY3,
87
 
    StringIO,
88
 
    text_type,
89
 
    )
90
 
 
91
84
 
92
85
# global verbosity for breezy; controls the log level for stderr; 0=normal; <0
93
86
# is quiet; >0 is verbose.
162
155
        fmt = fmt.decode('ascii', 'replace')
163
156
 
164
157
    if args:
165
 
        if not PY3:
166
 
            args = tuple(
167
 
                _Bytes(arg) if isinstance(arg, bytes) else arg for arg in args)
168
158
        out = fmt % args
169
159
    else:
170
160
        out = fmt
211
201
    :return: A path to the log file
212
202
    :raise EnvironmentError: If the cache directory could not be created
213
203
    """
214
 
    brz_log = osutils.path_from_environ('BRZ_LOG')
 
204
    brz_log = os.environ.get('BRZ_LOG')
215
205
    if brz_log:
216
206
        return brz_log
217
207
    return os.path.join(bedding.cache_dir(), 'brz.log')
306
296
        r'%Y-%m-%d %H:%M:%S')
307
297
    # after hooking output into brz_log, we also need to attach a stderr
308
298
    # handler, writing only at level info and with encoding
309
 
    if sys.version_info[0] == 2:
310
 
        stderr_handler = EncodedStreamHandler(
311
 
            sys.stderr, osutils.get_terminal_encoding(), 'replace',
312
 
            level=logging.INFO)
313
 
    else:
314
 
        stderr_handler = logging.StreamHandler(stream=sys.stderr)
 
299
    stderr_handler = logging.StreamHandler(stream=sys.stderr)
315
300
    logging.getLogger('brz').addHandler(stderr_handler)
316
301
    return memento
317
302
 
524
509
    elif not getattr(exc_object, 'internal_error', True):
525
510
        report_user_error(exc_info, err_file)
526
511
        return errors.EXIT_ERROR
527
 
    elif osutils.is_environment_error(exc_object):
 
512
    elif isinstance(exc_object, EnvironmentError):
528
513
        if getattr(exc_object, 'errno', None) == errno.EPIPE:
529
514
            err_file.write("brz: broken pipe\n")
530
515
            return errors.EXIT_ERROR
615
600
 
616
601
    def emit(self, record):
617
602
        try:
618
 
            if not isinstance(record.msg, text_type):
 
603
            if not isinstance(record.msg, str):
619
604
                msg = record.msg.decode("utf-8")
620
 
                if PY3:
621
 
                    record.msg = msg
 
605
                record.msg = msg
622
606
            line = self.format(record)
623
 
            if not isinstance(line, text_type):
 
607
            if not isinstance(line, str):
624
608
                line = line.decode("utf-8")
625
609
            self.stream.write(line.encode(self.encoding, self.errors) + b"\n")
626
610
        except Exception: