~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
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.
52
52
 
53
 
 
54
 
import errno
55
53
import os
56
54
import sys
 
55
import re
 
56
 
 
57
from bzrlib.lazy_import import lazy_import
 
58
lazy_import(globals(), """
 
59
import errno
57
60
import logging
 
61
""")
58
62
 
59
63
import bzrlib
60
 
from bzrlib.errors import BzrError, BzrNewError
61
64
from bzrlib.symbol_versioning import (deprecated_function,
62
65
        zero_nine,
63
66
        )
93
96
def mutter(fmt, *args):
94
97
    if _trace_file is None:
95
98
        return
96
 
    if hasattr(_trace_file, 'closed') and _trace_file.closed:
 
99
    if (getattr(_trace_file, 'closed', None) is not None) and _trace_file.closed:
97
100
        return
 
101
 
 
102
    if isinstance(fmt, unicode):
 
103
        fmt = fmt.encode('utf8')
 
104
 
98
105
    if len(args) > 0:
99
106
        # It seems that if we do ascii % (unicode, ascii) we can
100
107
        # get a unicode cannot encode ascii error, so make sure that "fmt"
101
108
        # is a unicode string
102
 
        out = unicode(fmt) % args
 
109
        real_args = []
 
110
        for arg in args:
 
111
            if isinstance(arg, unicode):
 
112
                arg = arg.encode('utf8')
 
113
            real_args.append(arg)
 
114
        out = fmt % tuple(real_args)
103
115
    else:
104
116
        out = fmt
105
117
    out += '\n'
106
 
    try:
107
 
        _trace_file.write(out)
108
 
    except UnicodeError, e:
109
 
        warning('UnicodeError: %s', e)
110
 
        _trace_file.write(repr(out))
 
118
    _trace_file.write(out)
111
119
    # TODO: jam 20051227 Consider flushing the trace file to help debugging
112
120
    #_trace_file.flush()
113
121
debug = mutter
137
145
    _rollover_trace_maybe(trace_fname)
138
146
    try:
139
147
        LINE_BUFFERED = 1
140
 
        tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
 
148
        #tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
 
149
        tf = open(trace_fname, 'at', LINE_BUFFERED)
141
150
        _bzr_log_file = tf
142
151
        if tf.tell() == 0:
143
152
            tf.write("\nthis is a debug log for diagnosing/reporting problems in bzr\n")
162
171
    """
163
172
    if msg:
164
173
        error(msg)
165
 
    else:
166
 
        exc_str = format_exception_short(sys.exc_info())
167
 
        error(exc_str)
168
174
    log_exception_quietly()
169
175
 
170
176
 
282
288
    """Report an exception that probably indicates a bug in bzr"""
283
289
    import traceback
284
290
    exc_type, exc_object, exc_tb = exc_info
285
 
    print >>err_file, "bzr: ERROR: %s: %s" % (exc_type, exc_object)
 
291
    print >>err_file, "bzr: ERROR: %s.%s: %s" % (
 
292
        exc_type.__module__, exc_type.__name__, exc_object)
286
293
    print >>err_file
287
294
    traceback.print_exception(exc_type, exc_object, exc_tb, file=err_file)
288
295
    print >>err_file