/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

  • Committer: Martin Pool
  • Date: 2008-01-22 07:28:45 UTC
  • mto: This revision was merged to the branch mainline in revision 3219.
  • Revision ID: mbp@sourcefrog.net-20080122072845-1ct7zakuje6w34j4
Remove _stderr_handler global

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
# FIXME: Unfortunately it turns out that python's logging module
50
50
# is quite expensive, even when the message is not printed by any handlers.
51
51
# We should perhaps change back to just simply doing it here.
 
52
#
 
53
# On the other hand, as of 1.2 we generally only call the mutter() statement
 
54
# if (according to debug_flags) we actually intend to write it.  So the
 
55
# increased cost of logging.py is not so bad, and we could standardize on
 
56
# that.
52
57
 
53
58
import codecs
54
59
import logging
77
82
    )
78
83
""")
79
84
 
80
 
# logging Handler writing to stderr
81
 
_stderr_handler = None
82
85
 
83
86
# global verbosity for bzrlib; controls the log level for stderr; 0=normal; <0
84
87
# is quiet; >0 is verbose.
226
229
    """Configure default logging: messages to stderr and debug to .bzr.log
227
230
    
228
231
    This should only be called once per process.
 
232
 
 
233
    Non-command-line programs embedding bzrlib do not need to call this.  They
 
234
    can instead either pass a file to _push_log_file, or act directly on
 
235
    logging.getLogger("bzr").
229
236
    
230
237
    Output can be redirected away by calling _push_log_file.
231
238
    """
232
 
    # TODO: this isn't really appropriate for Launchpad or other bzrlib
233
 
    # users, which might want more control on where the messages go.
234
 
    global _stderr_handler, _trace_file
235
239
    # create encoded wrapper around stderr
236
 
    writer_factory = codecs.getwriter(osutils.get_terminal_encoding())
237
 
    encoded_stderr = writer_factory(sys.stderr, errors='replace')
238
 
    # write >=info messages to stderr
239
 
    _stderr_handler = logging.StreamHandler(encoded_stderr)
240
 
    _stderr_handler.setLevel(logging.INFO)
241
240
    bzr_log_file = _open_bzr_log()
242
241
    _push_log_file(bzr_log_file,
243
242
        r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s',
244
243
        r'%Y-%m-%d %H:%M:%S')
245
244
    # after hooking output into bzr_log, we also need to attach a stderr
246
 
    # handler
247
 
    logging.getLogger('bzr').addHandler(_stderr_handler)
 
245
    # handler, writing only at level info and with encoding
 
246
    writer_factory = codecs.getwriter(osutils.get_terminal_encoding())
 
247
    encoded_stderr = writer_factory(sys.stderr, errors='replace')
 
248
    stderr_handler = logging.StreamHandler(encoded_stderr)
 
249
    stderr_handler.setLevel(logging.INFO)
 
250
    logging.getLogger('bzr').addHandler(stderr_handler)
248
251
 
249
252
 
250
253
def _push_log_file(to_file, log_format=None, date_format=None):
353
356
    # TODO: if this is not used, remove it.  if it is, maybe set the logger
354
357
    # level, rather than the handler level?
355
358
    if quiet:
356
 
        _stderr_handler.setLevel(logging.WARNING)
 
359
        _bzr_logger.setLevel(logging.WARNING)
357
360
    else:
358
 
        _stderr_handler.setLevel(logging.INFO)
 
361
        _bzr_logger.setLevel(logging.INFO)
359
362
 
360
363
 
361
364
def is_quiet():