~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
    _bzr_logger.error(*args, **kwargs)
146
146
 
147
147
 
148
 
def show_error(msg):
 
148
def show_error(*args, **kwargs):
149
149
    """Show an error message to the user.
150
150
 
151
151
    Don't use this for exceptions, use report_exception instead.
241
241
    _bzr_log_filename = _get_bzr_log_filename()
242
242
    _rollover_trace_maybe(_bzr_log_filename)
243
243
    try:
244
 
        bzr_log_file = open(_bzr_log_filename, 'at', buffering=0) # unbuffered
 
244
        buffering = 0 # unbuffered
 
245
        bzr_log_file = osutils.open_with_ownership(_bzr_log_filename, 'at', buffering)
245
246
        # bzr_log_file.tell() on windows always return 0 until some writing done
246
247
        bzr_log_file.write('\n')
247
248
        if bzr_log_file.tell() <= 2:
248
249
            bzr_log_file.write("this is a debug log for diagnosing/reporting problems in bzr\n")
249
250
            bzr_log_file.write("you can delete or truncate this file, or include sections in\n")
250
251
            bzr_log_file.write("bug reports to https://bugs.launchpad.net/bzr/+filebug\n\n")
 
252
 
251
253
        return bzr_log_file
 
254
 
252
255
    except IOError, e:
253
256
        # If we are failing to open the log, then most likely logging has not
254
257
        # been set up yet. So we just write to stderr rather than using
501
504
    """Report an exception that probably indicates a bug in bzr"""
502
505
    from bzrlib.crash import report_bug
503
506
    report_bug(exc_info, err_file)
 
507
 
 
508
 
 
509
def _flush_stdout_stderr():
 
510
    # installed into an atexit hook by bzrlib.initialize()
 
511
    try:
 
512
        sys.stdout.flush()
 
513
        sys.stderr.flush()
 
514
    except IOError, e:
 
515
        import errno
 
516
        if e.errno in [errno.EINVAL, errno.EPIPE]:
 
517
            pass
 
518
        else:
 
519
            raise
 
520
 
 
521
 
 
522
def _flush_trace():
 
523
    # run from atexit hook
 
524
    global _trace_file
 
525
    if _trace_file:
 
526
        _trace_file.flush()