~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-30 13:54:37 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1898.
  • Revision ID: john@arbash-meinel.com-20060730135437-1d722abdb14bff76
(jelmer) Install new intertree tests

Show diffs side-by-side

added added

removed removed

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