~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

merge merge tweaks from aaron, which includes latest .dev

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