~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Robert Collins
  • Date: 2005-10-08 00:39:04 UTC
  • mfrom: (1185.1.52)
  • Revision ID: robertc@robertcollins.net-20051008003904-aaffaea2778efe3e
merge in martins reweave, integrated to fetch, and a bugfix for commit and upgrade with executable files

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
# TODO: When running the test suites, we should add an additional
34
34
# logger that sends messages into the test log file.
35
35
 
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.
39
 
 
40
36
 
41
37
import sys
42
38
import os
156
152
          sys.platform)
157
153
 
158
154
    debug('  arguments: %r', argv)
159
 
    debug('  working dir: %r', os.getcwdu())
 
155
    debug('  working dir: %s', os.getcwdu())
160
156
 
161
157
 
162
158
def log_exception(msg=None):
163
 
    """Log the last exception to stderr and the trace file.
 
159
    """Log the last exception into the trace file.
164
160
 
165
161
    The exception string representation is used as the error
166
162
    summary, unless msg is given.
167
163
    """
168
 
    cmd_repr = ' '.join(repr(arg) for arg in sys.argv)
169
 
    cmd_info = '\n  command: %s\n  pwd: %s' \
170
 
        % (cmd_repr, os.getcwd())
171
164
    if msg == None:
172
165
        ei = sys.exc_info()
173
166
        msg = str(ei[1])
174
167
    if msg and (msg[-1] == '\n'):
175
168
        msg = msg[:-1]
176
169
    ## msg = "(%s) %s" % (str(type(ei[1])), msg)
177
 
    _bzr_logger.exception(msg + cmd_info)
178
 
 
179
 
 
180
 
 
181
 
def log_exception_quietly():
182
 
    """Log the last exception to the trace file only.
183
 
 
184
 
    Used for exceptions that occur internally and that may be 
185
 
    interesting to developers but not to users.  For example, 
186
 
    errors loading plugins.
187
 
    """
188
 
    debug(traceback.format_exc())
 
170
    _bzr_logger.exception(msg)
 
171
 
189
172
 
190
173
 
191
174
def enable_default_logging():