~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Aaron Bentley
  • Date: 2006-04-07 22:46:52 UTC
  • mfrom: (1645 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: aaron.bentley@utoronto.ca-20060407224652-4925bc3735b926f8
Merged latest bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
 
79
79
_bzr_logger = logging.getLogger('bzr')
80
80
 
81
 
info = note = _bzr_logger.info
82
 
warning =   _bzr_logger.warning
 
81
def note(*args, **kwargs):
 
82
    import bzrlib.ui
 
83
    bzrlib.ui.ui_factory.clear_term()
 
84
    _bzr_logger.info(*args, **kwargs)
 
85
 
 
86
def warning(*args, **kwargs):
 
87
    import bzrlib.ui
 
88
    bzrlib.ui.ui_factory.clear_term()
 
89
    _bzr_logger.warning(*args, **kwargs)
 
90
 
 
91
info = note
83
92
log_error = _bzr_logger.error
84
93
error =     _bzr_logger.error
85
94
 
219
228
 
220
229
 
221
230
def enable_test_log(to_file):
222
 
    """Redirect logging to a temporary file for a test"""
 
231
    """Redirect logging to a temporary file for a test
 
232
    
 
233
    returns an opaque reference that should be passed to disable_test_log
 
234
    after the test complete.
 
235
    """
223
236
    disable_default_logging()
224
 
    global _test_log_hdlr, _trace_file
 
237
    global _trace_file
225
238
    hdlr = logging.StreamHandler(to_file)
226
239
    hdlr.setLevel(logging.DEBUG)
227
240
    hdlr.setFormatter(logging.Formatter('%(levelname)8s  %(message)s'))
228
241
    _bzr_logger.addHandler(hdlr)
229
242
    _bzr_logger.setLevel(logging.DEBUG)
230
 
    _test_log_hdlr = hdlr
 
243
    result = hdlr, _trace_file
231
244
    _trace_file = to_file
232
 
 
233
 
 
234
 
def disable_test_log():
235
 
    _bzr_logger.removeHandler(_test_log_hdlr)
236
 
    _trace_file = None
 
245
    return result
 
246
 
 
247
 
 
248
def disable_test_log((test_log_hdlr, old_trace_file)):
 
249
    _bzr_logger.removeHandler(test_log_hdlr)
 
250
    _trace_file = old_trace_file
237
251
    enable_default_logging()
238
252
 
239
253