1
# Copyright (C) 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
50
50
# is quite expensive, even when the message is not printed by any handlers.
51
51
# We should perhaps change back to just simply doing it here.
57
from bzrlib.lazy_import import lazy_import
58
lazy_import(globals(), """
61
from bzrlib.errors import BzrError, BzrNewError
62
64
from bzrlib.symbol_versioning import (deprecated_function,
68
lazy_import(globals(), """
69
from bzrlib import debug
66
72
_file_handler = None
67
73
_stderr_handler = None
68
74
_stderr_quiet = False
71
77
_bzr_log_file = None
78
_bzr_log_filename = None
74
81
# configure convenient aliases for output routines
135
def open_tracefile(tracefilename='~/.bzr.log'):
141
def open_tracefile(tracefilename=None):
136
142
# Messages are always written to here, so that we have some
137
143
# information if something goes wrong. In a future version this
138
144
# file will be removed on successful completion.
139
global _file_handler, _bzr_log_file
145
global _file_handler, _bzr_log_file, _bzr_log_filename
142
trace_fname = os.path.join(os.path.expanduser(tracefilename))
143
_rollover_trace_maybe(trace_fname)
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)
145
159
LINE_BUFFERED = 1
146
160
#tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
147
tf = open(trace_fname, 'at', LINE_BUFFERED)
161
tf = open(_bzr_log_filename, 'at', LINE_BUFFERED)
148
162
_bzr_log_file = tf
150
tf.write("\nthis is a debug log for diagnosing/reporting problems in bzr\n")
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")
151
167
tf.write("you can delete or truncate this file, or include sections in\n")
152
tf.write("bug reports to bazaar-ng@lists.canonical.com\n\n")
168
tf.write("bug reports to bazaar@lists.canonical.com\n\n")
153
169
_file_handler = logging.StreamHandler(tf)
154
170
fmt = r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s'
155
171
datefmt = r'%a %H:%M:%S'
267
285
print >>err_file, "bzr: broken pipe"
268
286
elif isinstance(exc_object, KeyboardInterrupt):
269
287
print >>err_file, "bzr: interrupted"
270
elif getattr(exc_object, 'is_user_error', False):
288
elif not getattr(exc_object, 'internal_error', True):
271
289
report_user_error(exc_info, err_file)
272
290
elif isinstance(exc_object, (OSError, IOError)):
273
291
# Might be nice to catch all of these and show them as something more
280
298
# TODO: Should these be specially encoding the output?
281
299
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)
282
307
print >>err_file, "bzr: ERROR:", str(exc_info[1])
298
323
print >>err_file, 'arguments: %r' % sys.argv
300
print >>err_file, "** please send this report to bazaar-ng@lists.ubuntu.com"
325
print >>err_file, "** please send this report to bazaar@lists.ubuntu.com"