/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

Code and tests for shorter formatting of error messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
14
 
15
15
 
16
 
"""Messages and logging for bazaar-ng
17
 
 
18
 
Messages are sent out through the Python logging library.
19
 
 
20
 
They can be sent to two places: to stderr, and to ~/.bzr.log.
21
 
 
22
 
~/.bzr.log gets all messages, and tracebacks of all uncaught
23
 
exceptions.
24
 
 
25
 
Normally stderr only gets messages of level INFO and higher, and gets
26
 
only a summary of exceptions, not the traceback.
 
16
"""Messages and logging for bazaar-ng.
 
17
 
 
18
Messages are supplied by callers as a string-formatting template, plus values
 
19
to be inserted into it.  The actual %-formatting is deferred to the log
 
20
library so that it doesn't need to be done for messages that won't be emitted.
 
21
 
 
22
Messages are classified by severity levels: critical, error, warning, info,
 
23
and debug.
 
24
 
 
25
They can be sent to two places: to stderr, and to ~/.bzr.log.  For purposes
 
26
such as running the test suite, they can also be redirected away from both of
 
27
those two places to another location.
 
28
 
 
29
~/.bzr.log gets all messages, and full tracebacks for uncaught exceptions.
 
30
 
 
31
Output to stderr depends on the mode chosen by the user.  By default, messages
 
32
of info and above are sent out, which results in progress messages such as the
 
33
list of files processed by add and commit.  In quiet mode, only warnings and
 
34
above are shown.  In debug mode, stderr gets debug messages too.
 
35
 
 
36
Errors that terminate an operation are generally passed back as exceptions;
 
37
others may be just emitted as messages.
 
38
 
 
39
Exceptions are reported in a brief form to stderr so as not to look scary.
 
40
BzrErrors are required to be able to format themselves into a properly
 
41
explanatory message.  This is not true for builtin excexceptions such as
 
42
KeyError, which typically just str to "0".  They're printed in a different
 
43
form.
27
44
"""
28
45
 
29
46
 
219
236
    l.removeHandler(_stderr_handler)
220
237
    if _file_handler:
221
238
        l.removeHandler(_file_handler)
 
239
 
 
240
 
 
241
def format_exception_short():
 
242
    """Make a short string form of an exception.
 
243
 
 
244
    This is used for display to stderr.  It specially handles exception
 
245
    classes without useful string methods.
 
246
    """
 
247
    exc_type, exc_info, exc_tb = sys.exc_info()
 
248
    msg = None
 
249
    if msg == None:
 
250
        msg = str(exc_info)
 
251
    if msg and (msg[-1] == '\n'):
 
252
        msg = msg[:-1]
 
253
    ## msg += '\n  command: %s' % ' '.join(repr(arg) for arg in sys.argv)
 
254
    ## msg += '\n      pwd: %r' % os.getcwdu()
 
255
    ## msg += '\n    error: %s' % exc_type
 
256
    return msg