33
33
# TODO: When running the test suites, we should add an additional
34
34
# logger that sends messages into the test log file.
36
# FIXME: Unfortunately it turns out that python's logging module
37
# is quite expensive, even when the message is not printed by any handlers.
38
# We should perhaps change back to just simply doing it here.
85
81
# configure convenient aliases for output routines
87
83
_bzr_logger = logging.getLogger('bzr')
84
_bzr_logger.setLevel(logging.DEBUG)
89
86
info = note = _bzr_logger.info
90
87
warning = _bzr_logger.warning
157
154
debug(' arguments: %r', argv)
158
debug(' working dir: %r', os.getcwdu())
155
debug(' working dir: %s', os.getcwdu())
161
158
def log_exception(msg=None):
162
"""Log the last exception to stderr and the trace file.
159
"""Log the last exception into the trace file.
164
161
The exception string representation is used as the error
165
162
summary, unless msg is given.
164
command = ' '.join(repr(arg) for arg in sys.argv)
165
prefix = "command: %s\npwd: %s\n" % (command, os.getcwd())
170
169
if msg and (msg[-1] == '\n'):
172
msg += '\n command: %s' % ' '.join(repr(arg) for arg in sys.argv)
173
msg += '\n pwd: %r' % os.getcwdu()
174
msg += '\n error: %s' % ei[0] # exception type
175
_bzr_logger.exception(msg)
178
def log_exception_quietly():
179
"""Log the last exception to the trace file only.
181
Used for exceptions that occur internally and that may be
182
interesting to developers but not to users. For example,
183
errors loading plugins.
185
debug(traceback.format_exc())
171
## msg = "(%s) %s" % (str(type(ei[1])), msg)
172
_bzr_logger.exception(prefix + msg)
188
176
def enable_default_logging():