~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Martin Pool
  • Date: 2006-02-01 12:24:35 UTC
  • mfrom: (1534.4.32 branch-formats)
  • mto: This revision was merged to the branch mainline in revision 1553.
  • Revision ID: mbp@sourcefrog.net-20060201122435-53f3efb1b5749fe1
[merge] branch-formats branch, and reconcile changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
 
220
220
 
221
221
def enable_test_log(to_file):
222
 
    """Redirect logging to a temporary file for a test"""
 
222
    """Redirect logging to a temporary file for a test
 
223
    
 
224
    returns an opaque reference that should be passed to disable_test_log
 
225
    after the test complete.
 
226
    """
223
227
    disable_default_logging()
224
 
    global _test_log_hdlr, _trace_file
 
228
    global _trace_file
225
229
    hdlr = logging.StreamHandler(to_file)
226
230
    hdlr.setLevel(logging.DEBUG)
227
231
    hdlr.setFormatter(logging.Formatter('%(levelname)8s  %(message)s'))
228
232
    _bzr_logger.addHandler(hdlr)
229
233
    _bzr_logger.setLevel(logging.DEBUG)
230
 
    _test_log_hdlr = hdlr
 
234
    result = hdlr, _trace_file
231
235
    _trace_file = to_file
232
 
 
233
 
 
234
 
def disable_test_log():
235
 
    _bzr_logger.removeHandler(_test_log_hdlr)
236
 
    _trace_file = None
 
236
    return result
 
237
 
 
238
 
 
239
def disable_test_log((test_log_hdlr, old_trace_file)):
 
240
    _bzr_logger.removeHandler(test_log_hdlr)
 
241
    _trace_file = old_trace_file
237
242
    enable_default_logging()
238
243
 
239
244