~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

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