~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-24 14:12:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2095.
  • Revision ID: john@arbash-meinel.com-20061024141253-783fba812b197b70
(John Arbash Meinel) Update version information for 0.13 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        zero_nine,
66
66
        )
67
67
 
68
 
lazy_import(globals(), """
69
 
from bzrlib import debug
70
 
""")
71
 
 
72
68
_file_handler = None
73
69
_stderr_handler = None
74
70
_stderr_quiet = False
75
71
_trace_file = None
76
72
_trace_depth = 0
77
73
_bzr_log_file = None
78
 
_bzr_log_filename = None
79
74
 
80
75
 
81
76
# configure convenient aliases for output routines
123
118
    _trace_file.write(out)
124
119
    # TODO: jam 20051227 Consider flushing the trace file to help debugging
125
120
    #_trace_file.flush()
 
121
debug = mutter
126
122
 
127
123
 
128
124
def _rollover_trace_maybe(trace_fname):
138
134
        return
139
135
 
140
136
 
141
 
def open_tracefile(tracefilename=None):
 
137
def open_tracefile(tracefilename='~/.bzr.log'):
142
138
    # Messages are always written to here, so that we have some
143
139
    # information if something goes wrong.  In a future version this
144
140
    # file will be removed on successful completion.
145
 
    global _file_handler, _bzr_log_file, _bzr_log_filename
 
141
    global _file_handler, _bzr_log_file
146
142
    import codecs
147
143
 
148
 
    if tracefilename is None:
149
 
        if sys.platform == 'win32':
150
 
            from bzrlib import win32utils
151
 
            home = win32utils.get_home_location()
152
 
        else:
153
 
            home = os.path.expanduser('~')
154
 
        _bzr_log_filename = os.path.join(home, '.bzr.log')
155
 
 
156
 
    _bzr_log_filename = os.path.expanduser(_bzr_log_filename)
157
 
    _rollover_trace_maybe(_bzr_log_filename)
 
144
    trace_fname = os.path.join(os.path.expanduser(tracefilename))
 
145
    _rollover_trace_maybe(trace_fname)
158
146
    try:
159
147
        LINE_BUFFERED = 1
160
148
        #tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
161
 
        tf = open(_bzr_log_filename, 'at', LINE_BUFFERED)
 
149
        tf = open(trace_fname, 'at', LINE_BUFFERED)
162
150
        _bzr_log_file = tf
163
 
        # tf.tell() on windows always return 0 until some writing done
164
 
        tf.write('\n')
165
 
        if tf.tell() <= 2:
166
 
            tf.write("this is a debug log for diagnosing/reporting problems in bzr\n")
 
151
        if tf.tell() == 0:
 
152
            tf.write("\nthis is a debug log for diagnosing/reporting problems in bzr\n")
167
153
            tf.write("you can delete or truncate this file, or include sections in\n")
168
 
            tf.write("bug reports to bazaar@lists.canonical.com\n\n")
 
154
            tf.write("bug reports to bazaar-ng@lists.canonical.com\n\n")
169
155
        _file_handler = logging.StreamHandler(tf)
170
156
        fmt = r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s'
171
157
        datefmt = r'%a %H:%M:%S'
182
168
 
183
169
    The exception string representation is used as the error
184
170
    summary, unless msg is given.
185
 
 
186
 
    Please see log_exception_quietly() for the replacement API.
187
171
    """
188
172
    if msg:
189
173
        error(msg)
198
182
    errors loading plugins.
199
183
    """
200
184
    import traceback
201
 
    mutter(traceback.format_exc())
 
185
    debug(traceback.format_exc())
202
186
 
203
187
 
204
188
def enable_default_logging():
285
269
        print >>err_file, "bzr: broken pipe"
286
270
    elif isinstance(exc_object, KeyboardInterrupt):
287
271
        print >>err_file, "bzr: interrupted"
288
 
    elif not getattr(exc_object, 'internal_error', True):
 
272
    elif getattr(exc_object, 'is_user_error', False):
289
273
        report_user_error(exc_info, err_file)
290
274
    elif isinstance(exc_object, (OSError, IOError)):
291
275
        # Might be nice to catch all of these and show them as something more
297
281
 
298
282
# TODO: Should these be specially encoding the output?
299
283
def report_user_error(exc_info, err_file):
300
 
    """Report to err_file an error that's not an internal error.
301
 
 
302
 
    These don't get a traceback unless -Derror was given.
303
 
    """
304
 
    if 'error' in debug.debug_flags:
305
 
        report_bug(exc_info, err_file)
306
 
        return
307
284
    print >>err_file, "bzr: ERROR:", str(exc_info[1])
308
285
 
309
286
 
322
299
                        sys.platform)
323
300
    print >>err_file, 'arguments: %r' % sys.argv
324
301
    print >>err_file
325
 
    print >>err_file, "** please send this report to bazaar@lists.ubuntu.com"
 
302
    print >>err_file, "** please send this report to bazaar-ng@lists.ubuntu.com"