~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-22 21:39:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1953.
  • Revision ID: john@arbash-meinel.com-20060822213933-f993a9d069823426
Change mutter() so that it doesn't try so hard to write out perfect utf8, instead, rather than using a utf8 file, it changes unicode to utf8 manually

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
        return
96
96
    if hasattr(_trace_file, 'closed') and _trace_file.closed:
97
97
        return
 
98
 
 
99
    if isinstance(fmt, unicode):
 
100
        fmt = fmt.encode('utf8')
 
101
 
98
102
    if len(args) > 0:
99
103
        # It seems that if we do ascii % (unicode, ascii) we can
100
104
        # get a unicode cannot encode ascii error, so make sure that "fmt"
101
105
        # is a unicode string
102
 
        try:
103
 
            out = unicode(fmt) % args
104
 
        except UnicodeError, e:
105
 
            warning('WARNING: UnicodeError: %s', e)
106
 
            out_list = [fmt]
107
 
            out_list.extend(args)
108
 
            out = repr(out_list)
 
106
        real_args = []
 
107
        for arg in args:
 
108
            if isinstance(arg, unicode):
 
109
                arg = arg.encode('utf8')
 
110
            real_args.append(arg)
 
111
        out = fmt % tuple(real_args)
109
112
    else:
110
113
        out = fmt
111
114
    out += '\n'
112
 
    try:
113
 
        _trace_file.write(out)
114
 
    except UnicodeError, e:
115
 
        warning('WARNING: UnicodeError: %s', e)
116
 
        _trace_file.write(repr(out))
 
115
    _trace_file.write(out)
117
116
    # TODO: jam 20051227 Consider flushing the trace file to help debugging
118
117
    #_trace_file.flush()
119
118
debug = mutter
143
142
    _rollover_trace_maybe(trace_fname)
144
143
    try:
145
144
        LINE_BUFFERED = 1
146
 
        tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
 
145
        #tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
 
146
        tf = open(trace_fname, 'at', LINE_BUFFERED)
147
147
        _bzr_log_file = tf
148
148
        if tf.tell() == 0:
149
149
            tf.write("\nthis is a debug log for diagnosing/reporting problems in bzr\n")