235
235
def enable_default_logging():
236
236
"""Configure default logging: messages to stderr and debug to .bzr.log
238
238
This should only be called once per process.
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").
244
244
Output can be redirected away by calling _push_log_file.
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,
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)