141
def open_tracefile(tracefilename=None):
137
def open_tracefile(tracefilename='~/.bzr.log'):
142
138
# Messages are always written to here, so that we have some
143
139
# information if something goes wrong. In a future version this
144
140
# file will be removed on successful completion.
145
global _file_handler, _bzr_log_file, _bzr_log_filename
141
global _file_handler, _bzr_log_file
148
if tracefilename is None:
149
if sys.platform == 'win32':
150
from bzrlib import win32utils
151
home = win32utils.get_home_location()
153
home = os.path.expanduser('~')
154
_bzr_log_filename = os.path.join(home, '.bzr.log')
156
_bzr_log_filename = os.path.expanduser(_bzr_log_filename)
157
_rollover_trace_maybe(_bzr_log_filename)
144
trace_fname = os.path.join(os.path.expanduser(tracefilename))
145
_rollover_trace_maybe(trace_fname)
159
147
LINE_BUFFERED = 1
160
148
#tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
161
tf = open(_bzr_log_filename, 'at', LINE_BUFFERED)
149
tf = open(trace_fname, 'at', LINE_BUFFERED)
162
150
_bzr_log_file = tf
163
# tf.tell() on windows always return 0 until some writing done
166
tf.write("this is a debug log for diagnosing/reporting problems in bzr\n")
152
tf.write("\nthis is a debug log for diagnosing/reporting problems in bzr\n")
167
153
tf.write("you can delete or truncate this file, or include sections in\n")
168
tf.write("bug reports to bazaar@lists.canonical.com\n\n")
154
tf.write("bug reports to bazaar-ng@lists.canonical.com\n\n")
169
155
_file_handler = logging.StreamHandler(tf)
170
156
fmt = r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s'
171
157
datefmt = r'%a %H:%M:%S'
285
269
print >>err_file, "bzr: broken pipe"
286
270
elif isinstance(exc_object, KeyboardInterrupt):
287
271
print >>err_file, "bzr: interrupted"
288
elif not getattr(exc_object, 'internal_error', True):
272
elif getattr(exc_object, 'is_user_error', False):
289
273
report_user_error(exc_info, err_file)
290
274
elif isinstance(exc_object, (OSError, IOError)):
291
275
# Might be nice to catch all of these and show them as something more
298
282
# TODO: Should these be specially encoding the output?
299
283
def report_user_error(exc_info, err_file):
300
"""Report to err_file an error that's not an internal error.
302
These don't get a traceback unless -Derror was given.
304
if 'error' in debug.debug_flags:
305
report_bug(exc_info, err_file)
307
284
print >>err_file, "bzr: ERROR:", str(exc_info[1])
323
300
print >>err_file, 'arguments: %r' % sys.argv
325
print >>err_file, "** please send this report to bazaar@lists.ubuntu.com"
302
print >>err_file, "** please send this report to bazaar-ng@lists.ubuntu.com"