/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Aaron Bentley
  • Date: 2008-11-03 18:59:14 UTC
  • mfrom: (3818 +trunk)
  • mto: (0.16.99 shelf-ui)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081103185914-inz25vtsiowydw1p
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
234
234
 
235
235
def enable_default_logging():
236
236
    """Configure default logging: messages to stderr and debug to .bzr.log
237
 
    
 
237
 
238
238
    This should only be called once per process.
239
239
 
240
240
    Non-command-line programs embedding bzrlib do not need to call this.  They
241
241
    can instead either pass a file to _push_log_file, or act directly on
242
242
    logging.getLogger("bzr").
243
 
    
 
243
 
244
244
    Output can be redirected away by calling _push_log_file.
245
245
    """
 
246
    # Do this before we open the log file, so we prevent
 
247
    # get_terminal_encoding() from mutter()ing multiple times
 
248
    term_encoding = osutils.get_terminal_encoding()
 
249
    start_time = osutils.format_local_date(_bzr_log_start_time,
 
250
                                           timezone='local')
246
251
    # create encoded wrapper around stderr
247
252
    bzr_log_file = _open_bzr_log()
 
253
    bzr_log_file.write(start_time.encode('utf-8') + '\n')
248
254
    push_log_file(bzr_log_file,
249
255
        r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s',
250
256
        r'%Y-%m-%d %H:%M:%S')
251
257
    # after hooking output into bzr_log, we also need to attach a stderr
252
258
    # handler, writing only at level info and with encoding
253
 
    writer_factory = codecs.getwriter(osutils.get_terminal_encoding())
 
259
    writer_factory = codecs.getwriter(term_encoding)
254
260
    encoded_stderr = writer_factory(sys.stderr, errors='replace')
255
261
    stderr_handler = logging.StreamHandler(encoded_stderr)
256
262
    stderr_handler.setLevel(logging.INFO)