~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 05:53:44 UTC
  • mfrom: (2063 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006055344-e73b97b7c6ca6e72
[merge] bzr.dev 2063

Show diffs side-by-side

added added

removed removed

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