~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Martin Pool
  • Date: 2006-06-20 03:30:14 UTC
  • mfrom: (1793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mbp@sourcefrog.net-20060620033014-e19ce470e2ce6561
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
Exceptions are reported in a brief form to stderr so as not to look scary.
43
43
BzrErrors are required to be able to format themselves into a properly
44
 
explanatory message.  This is not true for builtin excexceptions such as
 
44
explanatory message.  This is not true for builtin exceptions such as
45
45
KeyError, which typically just str to "0".  They're printed in a different
46
46
form.
47
47
"""
95
95
    if hasattr(_trace_file, 'closed') and _trace_file.closed:
96
96
        return
97
97
    if len(args) > 0:
98
 
        out = fmt % args
 
98
        # It seems that if we do ascii % (unicode, ascii) we can
 
99
        # get a unicode cannot encode ascii error, so make sure that "fmt"
 
100
        # is a unicode string
 
101
        out = unicode(fmt) % args
99
102
    else:
100
103
        out = fmt
101
104
    out += '\n'
102
 
    _trace_file.write(out)
 
105
    try:
 
106
        _trace_file.write(out)
 
107
    except UnicodeError, e:
 
108
        warning('UnicodeError: %s', e)
 
109
        _trace_file.write(repr(out))
 
110
    # TODO: jam 20051227 Consider flushing the trace file to help debugging
 
111
    #_trace_file.flush()
103
112
debug = mutter
104
113
 
105
114