~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Robert Collins
  • Date: 2007-05-07 16:48:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2485.
  • Revision ID: robertc@robertcollins.net-20070507164814-wpagonutf4b5cf8s
Move HACKING to docs/developers/HACKING and adjust Makefile to accomodate this.

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