~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-22 15:44:59 UTC
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070722154459-520ws2gnifghkpgy
From review comments, use a private scheme for testing.

* bzrlib/transport/__init__.py:
(_unregister_urlparse_netloc_protocol): New function.

* bzrlib/tests/transport_util.py:
(InstrumentedTransport.__init__): Use a dedicated scheme.
(TestCaseWithConnectionHookedTransport.setUp): Reworked to
register the new transport.
(TestCaseWithConnectionHookedTransport.get_url): Use our dedicated
scheme.
(TestCaseWithConnectionHookedTransport.install_hooks,
TestCaseWithConnectionHookedTransport.reset_hooks): Registering
transport is setUp job.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
from bzrlib.lazy_import import lazy_import
58
58
lazy_import(globals(), """
59
 
from cStringIO import StringIO
60
59
import errno
61
60
import logging
62
 
import traceback
63
61
""")
64
62
 
65
63
import bzrlib
 
64
from bzrlib.symbol_versioning import (deprecated_function,
 
65
        zero_nine,
 
66
        )
66
67
 
67
68
lazy_import(globals(), """
68
69
from bzrlib import debug
124
125
    #_trace_file.flush()
125
126
 
126
127
 
127
 
def mutter_callsite(stacklevel, fmt, *args):
128
 
    """Perform a mutter of fmt and args, logging the call trace.
129
 
 
130
 
    :param stacklevel: The number of frames to show. None will show all
131
 
        frames.
132
 
    :param fmt: The format string to pass to mutter.
133
 
    :param args: A list of substitution variables.
134
 
    """
135
 
    outf = StringIO()
136
 
    traceback.print_stack(limit=stacklevel + 1, file=outf)
137
 
    formatted_lines = outf.getvalue().splitlines()
138
 
    formatted_stack = '\n'.join(formatted_lines[:-2])
139
 
    mutter(fmt + "\nCalled from:\n%s", *(args + (formatted_stack,)))
140
 
 
141
 
 
142
128
def _rollover_trace_maybe(trace_fname):
143
129
    import stat
144
130
    try:
166
152
        else:
167
153
            home = os.path.expanduser('~')
168
154
        _bzr_log_filename = os.path.join(home, '.bzr.log')
169
 
    else:
170
 
        _bzr_log_filename = tracefilename
171
155
 
172
156
    _bzr_log_filename = os.path.expanduser(_bzr_log_filename)
173
157
    _rollover_trace_maybe(_bzr_log_filename)
192
176
        warning("failed to open trace file: %s" % (e))
193
177
 
194
178
 
 
179
@deprecated_function(zero_nine)
 
180
def log_exception(msg=None):
 
181
    """Log the last exception to stderr and the trace file.
 
182
 
 
183
    The exception string representation is used as the error
 
184
    summary, unless msg is given.
 
185
 
 
186
    Please see log_exception_quietly() for the replacement API.
 
187
    """
 
188
    if msg:
 
189
        error(msg)
 
190
    log_exception_quietly()
 
191
 
 
192
 
195
193
def log_exception_quietly():
196
194
    """Log the last exception to the trace file only.
197
195