~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-01-08 19:59:01 UTC
  • mfrom: (3928.2.1 flush_bzr_log)
  • Revision ID: pqm@pqm.ubuntu.com-20090108195901-lechto0ubxsirqrd
(jam) Flush the trace file during mutter() every 2s or so.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
error =     _bzr_logger.error
132
132
 
133
133
 
 
134
_last_mutter_flush_time = None
 
135
 
134
136
def mutter(fmt, *args):
 
137
    global _last_mutter_flush_time
135
138
    if _trace_file is None:
136
139
        return
137
140
    if (getattr(_trace_file, 'closed', None) is not None) and _trace_file.closed:
152
155
        out = fmt % tuple(real_args)
153
156
    else:
154
157
        out = fmt
155
 
    timestamp = '%0.3f  ' % (time.time() - _bzr_log_start_time,)
 
158
    now = time.time()
 
159
    timestamp = '%0.3f  ' % (now - _bzr_log_start_time,)
156
160
    out = timestamp + out + '\n'
157
161
    _trace_file.write(out)
158
 
    # no need to flush here, the trace file is now linebuffered when it's
159
 
    # opened.
 
162
    # We flush if we haven't flushed for a few seconds. We don't want to flush
 
163
    # on every mutter, but when a command takes a while, it can be nice to see
 
164
    # updates in the debug log.
 
165
    if (_last_mutter_flush_time is None
 
166
        or (now - _last_mutter_flush_time) > 2.0):
 
167
        flush = getattr(_trace_file, 'flush', None)
 
168
        if flush is not None:
 
169
            flush()
 
170
        _last_mutter_flush_time = now
160
171
 
161
172
 
162
173
def mutter_callsite(stacklevel, fmt, *args):