/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:
111
111
 
112
112
 
113
113
def note(*args, **kwargs):
 
114
    """Output a note to the user.
 
115
 
 
116
    Takes the same parameters as logging.info.
 
117
 
 
118
    :return: None
 
119
    """
114
120
    # FIXME note always emits utf-8, regardless of the terminal encoding
115
121
    #
116
122
    # FIXME: clearing the ui and then going through the abstract logging
301
307
 
302
308
    Output can be redirected away by calling _push_log_file.
303
309
    """
304
 
    # Do this before we open the log file, so we prevent
305
 
    # get_terminal_encoding() from mutter()ing multiple times
306
 
    term_encoding = osutils.get_terminal_encoding()
307
310
    start_time = osutils.format_local_date(_bzr_log_start_time,
308
311
                                           timezone='local')
309
312
    # create encoded wrapper around stderr
315
318
        r'%Y-%m-%d %H:%M:%S')
316
319
    # after hooking output into bzr_log, we also need to attach a stderr
317
320
    # handler, writing only at level info and with encoding
 
321
    term_encoding = osutils.get_terminal_encoding()
318
322
    writer_factory = codecs.getwriter(term_encoding)
319
323
    encoded_stderr = writer_factory(sys.stderr, errors='replace')
320
324
    stderr_handler = logging.StreamHandler(encoded_stderr)
368
372
    _trace_file = old_trace_file
369
373
    bzr_logger = logging.getLogger('bzr')
370
374
    bzr_logger.removeHandler(new_handler)
371
 
    # 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
372
376
    # file will likely already be closed underneath.
373
377
    new_handler.close()
374
378
    bzr_logger.handlers = old_handlers
492
496
    elif not getattr(exc_object, 'internal_error', True):
493
497
        report_user_error(exc_info, err_file)
494
498
        return errors.EXIT_ERROR
495
 
    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"):
496
502
        # Might be nice to catch all of these and show them as something more
497
503
        # specific, but there are too many cases at the moment.
498
504
        report_user_error(exc_info, err_file)
532
538
 
533
539
 
534
540
def _flush_stdout_stderr():
535
 
    # installed into an atexit hook by bzrlib.initialize()
 
541
    # called from the bzrlib library finalizer returned by bzrlib.initialize()
536
542
    try:
537
543
        sys.stdout.flush()
538
544
        sys.stderr.flush()
545
551
 
546
552
 
547
553
def _flush_trace():
548
 
    # run from atexit hook
 
554
    # called from the bzrlib library finalizer returned by bzrlib.initialize()
549
555
    global _trace_file
550
556
    if _trace_file:
551
557
        _trace_file.flush()