/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 bzrlib/trace.py

  • Committer: Robert Collins
  • Date: 2010-06-25 20:34:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5324.
  • Revision ID: robertc@robertcollins.net-20100625203405-c74lxd3enklhaqf9
``bzrlib.osutils.get_terminal_encoding`` will now only mutter its
selection when explicitly requested; this avoids many duplicate calls
being logged when helpers, wrappers and older code that manually calls
it are executed it is now logged deliberately by the ui setup code.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
307
307
 
308
308
    Output can be redirected away by calling _push_log_file.
309
309
    """
310
 
    # Do this before we open the log file, so we prevent
311
 
    # get_terminal_encoding() from mutter()ing multiple times
312
 
    term_encoding = osutils.get_terminal_encoding()
313
310
    start_time = osutils.format_local_date(_bzr_log_start_time,
314
311
                                           timezone='local')
315
312
    # create encoded wrapper around stderr
321
318
        r'%Y-%m-%d %H:%M:%S')
322
319
    # after hooking output into bzr_log, we also need to attach a stderr
323
320
    # handler, writing only at level info and with encoding
 
321
    term_encoding = osutils.get_terminal_encoding()
324
322
    writer_factory = codecs.getwriter(term_encoding)
325
323
    encoded_stderr = writer_factory(sys.stderr, errors='replace')
326
324
    stderr_handler = logging.StreamHandler(encoded_stderr)
374
372
    _trace_file = old_trace_file
375
373
    bzr_logger = logging.getLogger('bzr')
376
374
    bzr_logger.removeHandler(new_handler)
377
 
    # must be closed, otherwise logging will try to close it atexit, and the
 
375
    # must be closed, otherwise logging will try to close it at exit, and the
378
376
    # file will likely already be closed underneath.
379
377
    new_handler.close()
380
378
    bzr_logger.handlers = old_handlers
498
496
    elif not getattr(exc_object, 'internal_error', True):
499
497
        report_user_error(exc_info, err_file)
500
498
        return errors.EXIT_ERROR
501
 
    elif isinstance(exc_object, (OSError, IOError)):
 
499
    elif isinstance(exc_object, (OSError, IOError)) or (
 
500
        # GZ 2010-05-20: Like (exc_type is pywintypes.error) but avoid import
 
501
        exc_type.__name__ == "error" and exc_type.__module__ == "pywintypes"):
502
502
        # Might be nice to catch all of these and show them as something more
503
503
        # specific, but there are too many cases at the moment.
504
504
        report_user_error(exc_info, err_file)
538
538
 
539
539
 
540
540
def _flush_stdout_stderr():
541
 
    # installed into an atexit hook by bzrlib.initialize()
 
541
    # called from the bzrlib library finalizer returned by bzrlib.initialize()
542
542
    try:
543
543
        sys.stdout.flush()
544
544
        sys.stderr.flush()
551
551
 
552
552
 
553
553
def _flush_trace():
554
 
    # run from atexit hook
 
554
    # called from the bzrlib library finalizer returned by bzrlib.initialize()
555
555
    global _trace_file
556
556
    if _trace_file:
557
557
        _trace_file.flush()