~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Andrew Bennetts
  • Date: 2009-12-03 05:57:41 UTC
  • mfrom: (4857 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4869.
  • Revision ID: andrew.bennetts@canonical.com-20091203055741-vmmg0fmjgjw2pwvu
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
153
153
    _bzr_logger.error(*args, **kwargs)
154
154
 
155
155
 
156
 
_last_mutter_flush_time = None
157
 
 
158
 
 
159
156
def mutter(fmt, *args):
160
 
    global _last_mutter_flush_time
161
157
    if _trace_file is None:
162
158
        return
 
159
    # XXX: Don't check this every time; instead anyone who closes the file
 
160
    # ought to deregister it.  We can tolerate None.
163
161
    if (getattr(_trace_file, 'closed', None) is not None) and _trace_file.closed:
164
162
        return
165
163
 
182
180
    timestamp = '%0.3f  ' % (now - _bzr_log_start_time,)
183
181
    out = timestamp + out + '\n'
184
182
    _trace_file.write(out)
185
 
    # We flush if we haven't flushed for a few seconds. We don't want to flush
186
 
    # on every mutter, but when a command takes a while, it can be nice to see
187
 
    # updates in the debug log.
188
 
    if (_last_mutter_flush_time is None
189
 
        or (now - _last_mutter_flush_time) > 2.0):
190
 
        flush = getattr(_trace_file, 'flush', None)
191
 
        if flush is not None:
192
 
            flush()
193
 
        _last_mutter_flush_time = now
 
183
    # there's no explicit flushing; the file is typically line buffered.
194
184
 
195
185
 
196
186
def mutter_callsite(stacklevel, fmt, *args):
251
241
    _bzr_log_filename = _get_bzr_log_filename()
252
242
    _rollover_trace_maybe(_bzr_log_filename)
253
243
    try:
254
 
        bzr_log_file = open(_bzr_log_filename, 'at', 1) # line buffered
 
244
        bzr_log_file = open(_bzr_log_filename, 'at', buffering=0) # unbuffered
255
245
        # bzr_log_file.tell() on windows always return 0 until some writing done
256
246
        bzr_log_file.write('\n')
257
247
        if bzr_log_file.tell() <= 2:
445
435
 
446
436
    :return: The appropriate exit code for this error.
447
437
    """
448
 
    exc_type, exc_object, exc_tb = exc_info
449
438
    # Log the full traceback to ~/.bzr.log
450
439
    log_exception_quietly()
 
440
    if 'error' in debug.debug_flags:
 
441
        print_exception(exc_info, err_file)
 
442
        return errors.EXIT_ERROR
 
443
    exc_type, exc_object, exc_tb = exc_info
451
444
    if (isinstance(exc_object, IOError)
452
445
        and getattr(exc_object, 'errno', None) == errno.EPIPE):
453
446
        err_file.write("bzr: broken pipe\n")
494
487
    :param advice: Extra advice to the user to be printed following the
495
488
        exception.
496
489
    """
497
 
    if 'error' in debug.debug_flags:
498
 
        print_exception(exc_info, err_file)
499
 
        return
500
490
    err_file.write("bzr: ERROR: %s\n" % (exc_info[1],))
501
491
    if advice:
502
492
        err_file.write("%s\n" % (advice,))