~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
        return
138
138
 
139
139
 
140
 
def open_tracefile(tracefilename='~/.bzr.log'):
 
140
def open_tracefile(tracefilename=None):
141
141
    # Messages are always written to here, so that we have some
142
142
    # information if something goes wrong.  In a future version this
143
143
    # file will be removed on successful completion.
144
144
    global _file_handler, _bzr_log_file
145
145
    import codecs
146
146
 
147
 
    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)
148
156
    _rollover_trace_maybe(trace_fname)
149
157
    try:
150
158
        LINE_BUFFERED = 1
151
159
        #tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
152
160
        tf = open(trace_fname, 'at', LINE_BUFFERED)
153
161
        _bzr_log_file = tf
154
 
        if tf.tell() == 0:
155
 
            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")
156
166
            tf.write("you can delete or truncate this file, or include sections in\n")
157
167
            tf.write("bug reports to bazaar@lists.canonical.com\n\n")
158
168
        _file_handler = logging.StreamHandler(tf)