/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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

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