~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Aaron Bentley
  • Date: 2005-10-20 02:57:55 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1474.
  • Revision ID: aaron.bentley@utoronto.ca-20051020025755-e03df41c52aa3156
tweaked spacing

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
 
36
40
 
37
41
import sys
38
42
import os
54
58
    # can get the exception details is we suppress them here.
55
59
 
56
60
    def format(self, record):
57
 
        s = 'bzr: '
58
61
        if record.levelno >= logging.WARNING:
59
 
            s += record.levelname + ': '
 
62
            s = 'bzr: ' + record.levelname + ': '
 
63
        else:
 
64
            s = ''
60
65
            
61
 
        s += record.getMessage() 
 
66
        s += record.getMessage()
 
67
 
 
68
        ##import textwrap
 
69
        ##s = textwrap.fill(s)
62
70
            
63
71
        if record.exc_info:
64
72
            # give just a summary of the exception, not the whole thing
101
109
            return
102
110
        old_fname = trace_fname + '.old'
103
111
 
104
 
        try:
105
 
            # must remove before rename on windows
106
 
            os.remove(old_fname)
107
 
        except OSError:
108
 
            pass
 
112
        from osutils import rename
 
113
        rename(trace_fname, old_fname)
109
114
 
110
 
        try:
111
 
            # might fail if in use on windows
112
 
            os.rename(trace_fname, old_fname)
113
 
        except OSError:
114
 
            pass
115
115
    except OSError:
116
116
        return
117
117
 
156
156
          sys.platform)
157
157
 
158
158
    debug('  arguments: %r', argv)
159
 
    debug('  working dir: %s', os.getcwdu())
 
159
    debug('  working dir: %r', os.getcwdu())
160
160
 
161
161
 
162
162
def log_exception(msg=None):
165
165
    The exception string representation is used as the error
166
166
    summary, unless msg is given.
167
167
    """
 
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())
168
171
    if msg == None:
169
172
        ei = sys.exc_info()
170
173
        msg = str(ei[1])
171
 
 
172
174
    if msg and (msg[-1] == '\n'):
173
175
        msg = msg[:-1]
174
 
        
175
 
    _bzr_logger.exception(msg)
 
176
    ## msg = "(%s) %s" % (str(type(ei[1])), msg)
 
177
    _bzr_logger.exception(msg + cmd_info)
176
178
 
177
179
 
178
180