90
90
# than push/pop_log_file.
93
# File-like handle and filename for ~/.bzr.log. These aren't changed even if
94
# the log/trace output is redirected elsewhere. Used to show the location in
93
# Absolute path for ~/.bzr.log. Not changed even if the log/trace output is
94
# redirected elsewhere. Used to show the location in --version.
97
95
_bzr_log_filename = None
99
97
# The time the first message was written to the trace file, so that we can
202
201
.bzr.log.old and a new file is started. Otherwise, we append to the
205
This sets the globals _bzr_log_file and _bzr_log_filename.
204
This sets the global _bzr_log_filename.
207
# TODO: What should happen if we fail to open the trace file? Maybe the
208
# objects should be pointed at /dev/null or the equivalent?
209
global _bzr_log_file, _bzr_log_filename
206
global _bzr_log_filename
211
207
_bzr_log_filename = _get_bzr_log_filename()
212
208
_rollover_trace_maybe(_bzr_log_filename)
214
tf = open(_bzr_log_filename, 'at', 1) # line buffered
216
# tf.tell() on windows always return 0 until some writing done
219
tf.write("this is a debug log for diagnosing/reporting problems in bzr\n")
220
tf.write("you can delete or truncate this file, or include sections in\n")
221
tf.write("bug reports to https://bugs.launchpad.net/bzr/+filebug\n\n")
210
bzr_log_file = open(_bzr_log_filename, 'at', 1) # line buffered
211
# bzr_log_file.tell() on windows always return 0 until some writing done
212
bzr_log_file.write('\n')
213
if bzr_log_file.tell() <= 2:
214
bzr_log_file.write("this is a debug log for diagnosing/reporting problems in bzr\n")
215
bzr_log_file.write("you can delete or truncate this file, or include sections in\n")
216
bzr_log_file.write("bug reports to https://bugs.launchpad.net/bzr/+filebug\n\n")
222
218
except IOError, e:
223
219
warning("failed to open trace file: %s" % (e))
220
# TODO: What should happen if we fail to open the trace file? Maybe the
221
# objects should be pointed at /dev/null or the equivalent? Currently
222
# returns None which will cause failures later.
226
225
def enable_default_logging():
233
232
# TODO: this isn't really appropriate for Launchpad or other bzrlib
234
233
# users, which might want more control on where the messages go.
235
global _stderr_handler, _trace_file, _bzr_log_file
234
global _stderr_handler, _trace_file
236
235
# create encoded wrapper around stderr
237
236
writer_factory = codecs.getwriter(osutils.get_terminal_encoding())
238
237
encoded_stderr = writer_factory(sys.stderr, errors='replace')
239
238
# write >=info messages to stderr
240
239
_stderr_handler = logging.StreamHandler(encoded_stderr)
241
240
_stderr_handler.setLevel(logging.INFO)
243
_push_log_file(_bzr_log_file,
241
bzr_log_file = _open_bzr_log()
242
_push_log_file(bzr_log_file,
244
243
r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s',
245
244
r'%Y-%m-%d %H:%M:%S')
246
245
# after hooking output into bzr_log, we also need to attach a stderr