[Python-checkins] python/dist/src/Lib/logging __init__.py, 1.14,
1.15
vsajip at users.sourceforge.net
vsajip at users.sourceforge.net
Sat Jul 3 07:47:29 EDT 2004
Update of /cvsroot/python/python/dist/src/Lib/logging
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27566
Modified Files:
__init__.py
Log Message:
Changed basicConfig() to add keyword arguments. Changes are backward-compatible.
Added error checking to log() to check that level is an integer, and raise a TypeError if not (as long as raiseExceptions is set).
Minor documentation corrections.
Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/logging/__init__.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** __init__.py 28 Feb 2004 16:03:58 -0000 1.14
--- __init__.py 3 Jul 2004 11:47:26 -0000 1.15
***************
*** 37,42 ****
__author__ = "Vinay Sajip <vinay_sajip at red-dove.com>"
__status__ = "beta"
! __version__ = "0.4.9.2"
! __date__ = "28 February 2004"
#---------------------------------------------------------------------------
--- 37,42 ----
__author__ = "Vinay Sajip <vinay_sajip at red-dove.com>"
__status__ = "beta"
! __version__ = "0.4.9.3"
! __date__ = "03 July 2004"
#---------------------------------------------------------------------------
***************
*** 114,119 ****
INFO, DEBUG) then you get the corresponding string. If you have
associated levels with names using addLevelName then the name you have
! associated with 'level' is returned. Otherwise, the string
! "Level %s" % level is returned.
"""
return _levelNames.get(level, ("Level %s" % level))
--- 114,123 ----
INFO, DEBUG) then you get the corresponding string. If you have
associated levels with names using addLevelName then the name you have
! associated with 'level' is returned.
!
! If a numeric value corresponding to one of the defined levels is passed
! in, the corresponding string representation is returned.
!
! Otherwise, the string "Level %s" % level is returned.
"""
return _levelNames.get(level, ("Level %s" % level))
***************
*** 969,972 ****
--- 973,981 ----
logger.log(level, "We have a %s", "mysterious problem", exc_info=1)
"""
+ if type(level) != types.IntType:
+ if raiseExceptions:
+ raise TypeError, "level must be an integer"
+ else:
+ return
if self.manager.disable >= level:
return
***************
*** 1107,1121 ****
BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
! def basicConfig():
"""
! Do basic configuration for the logging system by creating a
! StreamHandler with a default Formatter and adding it to the
! root logger.
"""
if len(root.handlers) == 0:
! hdlr = StreamHandler()
! fmt = Formatter(BASIC_FORMAT)
hdlr.setFormatter(fmt)
root.addHandler(hdlr)
#---------------------------------------------------------------------------
--- 1116,1167 ----
BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
! def basicConfig(**kwargs):
"""
! Do basic configuration for the logging system.
!
! This function does nothing if the root logger already has handlers
! configured. It is a convenience method intended for use by simple scripts
! to do one-shot configuration of the logging package.
!
! The default behaviour is to create a StreamHandler which writes to
! sys.stderr, set a formatter using the BASIC_FORMAT format string, and
! add the handler to the root logger.
!
! A number of optional keyword arguments may be specified, which can alter
! the default behaviour.
!
! filename Specifies that a FileHandler be created, using the specified
! filename, rather than a StreamHandler.
! filemode Specifies the mode to open the file, if filename is specified
! (if filemode is unspecified, it defaults to "a").
! format Use the specified format string for the handler.
! datefmt Use the specified date/time format.
! level Set the root logger level to the specified level.
! stream Use the specified stream to initialize the StreamHandler. Note
! that this argument is incompatible with 'filename' - if both
! are present, 'stream' is ignored.
!
! Note that you could specify a stream created using open(filename, mode)
! rather than passing the filename and mode in. However, it should be
! remembered that StreamHandler does not close its stream (since it may be
! using sys.stdout or sys.stderr), whereas FileHandler closes its stream
! when the handler is closed.
"""
if len(root.handlers) == 0:
! filename = kwargs.get("filename")
! if filename:
! mode = kwargs.get("filemode", "a")
! hdlr = FileHandler(filename, mode)
! else:
! stream = kwargs.get("stream")
! hdlr = StreamHandler(stream)
! fs = kwargs.get("format", BASIC_FORMAT)
! dfs = kwargs.get("datefmt", None)
! fmt = Formatter(fs, dfs)
hdlr.setFormatter(fmt)
root.addHandler(hdlr)
+ level = kwargs.get("level")
+ if level:
+ root.setLevel(level)
#---------------------------------------------------------------------------
More information about the Python-checkins
mailing list