summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-04-11 16:25:06 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-04-11 16:25:06 (GMT)
commit22005fc5bad9d2c3eda9defb28e6a56ede4b2c8a (patch)
tree17d41ef1d9ad985eb0d849e88eb52fcafd1b90cd /Lib/logging
parent135e990a75dc7ff36ae9c9c8bb6a140490b2750c (diff)
downloadcpython-22005fc5bad9d2c3eda9defb28e6a56ede4b2c8a.zip
cpython-22005fc5bad9d2c3eda9defb28e6a56ede4b2c8a.tar.gz
cpython-22005fc5bad9d2c3eda9defb28e6a56ede4b2c8a.tar.bz2
Merged revisions 79279,79284,79293,79373,79376,79379,79876,79888 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79279 | vinay.sajip | 2010-03-22 07:33:08 -0500 (Mon, 22 Mar 2010) | 1 line Issue #8200: logging: Handle errors when multiprocessing is not fully loaded when logging occurs. ........ r79284 | vinay.sajip | 2010-03-22 08:02:28 -0500 (Mon, 22 Mar 2010) | 1 line Issue #8201: logging: Handle config errors when non-ASCII and Unicode logger names exist at the same time. ........ r79293 | vinay.sajip | 2010-03-22 10:29:01 -0500 (Mon, 22 Mar 2010) | 1 line logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter. ........ r79373 | vinay.sajip | 2010-03-24 09:31:21 -0500 (Wed, 24 Mar 2010) | 1 line logging: Added LOG_FTP for SysLogHandler and updated documentation. ........ r79376 | vinay.sajip | 2010-03-24 10:10:40 -0500 (Wed, 24 Mar 2010) | 1 line logging: Documentation tweak. ........ r79379 | vinay.sajip | 2010-03-24 12:36:35 -0500 (Wed, 24 Mar 2010) | 1 line logging: Updated SysLogHandler documentation. ........ r79876 | vinay.sajip | 2010-04-06 17:32:37 -0500 (Tue, 06 Apr 2010) | 1 line Issue #8327: logging: Clarification of propagation functionality in documentation. ........ r79888 | vinay.sajip | 2010-04-07 04:40:52 -0500 (Wed, 07 Apr 2010) | 1 line Issue #8331: logging: fixed some grammatical errors in documentation. ........
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py39
-rw-r--r--Lib/logging/config.py7
-rw-r--r--Lib/logging/handlers.py4
3 files changed, 44 insertions, 6 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index d9cd143..dca0017 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -285,10 +285,18 @@ class LogRecord(object):
self.threadName = None
if not logMultiprocessing:
self.processName = None
- elif 'multiprocessing' not in sys.modules:
- self.processName = 'MainProcess'
else:
- self.processName = sys.modules['multiprocessing'].current_process().name
+ self.processName = 'MainProcess'
+ mp = sys.modules.get('multiprocessing')
+ if mp is not None:
+ # Errors may occur if multiprocessing has not finished loading
+ # yet - e.g. if a custom import hook causes third-party code
+ # to run when multiprocessing calls import. See issue 8200
+ # for an example
+ try:
+ self.processName = mp.current_process().name
+ except StandardError:
+ pass
if logProcesses and hasattr(os, 'getpid'):
self.process = os.getpid()
else:
@@ -1306,6 +1314,25 @@ class Logger(Filterer):
return 0
return level >= self.getEffectiveLevel()
+ def getChild(self, suffix):
+ """
+ Get a logger which is a descendant to this one.
+
+ This is a convenience method, such that
+
+ logging.getLogger('abc').getChild('def.ghi')
+
+ is the same as
+
+ logging.getLogger('abc.def.ghi')
+
+ It's useful, for example, when the parent logger is named using
+ __name__ rather than a literal string.
+ """
+ if self.root is not self:
+ suffix = '.'.join((self.name, suffix))
+ return self.manager.getLogger(suffix)
+
class RootLogger(Logger):
"""
A root logger is not that different to any other logger, except that
@@ -1410,6 +1437,12 @@ class LoggerAdapter(object):
msg, kwargs = self.process(msg, kwargs)
self.logger.log(level, msg, *args, **kwargs)
+ def isEnabledFor(self, level):
+ """
+ See if the underlying logger is enabled for the specified level.
+ """
+ return self.logger.isEnabledFor(level)
+
root = RootLogger(WARNING)
Logger.root = root
Logger.manager = Manager(Logger.root)
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index beb51e5..f5971c2 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -98,6 +98,9 @@ def _resolve(name):
def _strip_spaces(alist):
return map(lambda x: x.strip(), alist)
+def _encoded(s):
+ return s if isinstance(s, str) else s.encode('utf-8')
+
def _create_formatters(cp):
"""Create and return formatters"""
flist = cp.get("formatters", "keys")
@@ -208,7 +211,7 @@ def _install_loggers(cp, handlers, disable_existing_loggers):
#avoid disabling child loggers of explicitly
#named loggers. With a sorted list it is easier
#to find the child loggers.
- existing.sort()
+ existing.sort(key=_encoded)
#We'll keep the list of existing loggers
#which are children of named loggers here...
child_loggers = []
@@ -579,7 +582,7 @@ class DictConfigurator(BaseConfigurator):
#avoid disabling child loggers of explicitly
#named loggers. With a sorted list it is easier
#to find the child loggers.
- existing.sort()
+ existing.sort(key=_encoded)
#We'll keep the list of existing loggers
#which are children of named loggers here...
child_loggers = []
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 692d104..a30dbdd 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -633,7 +633,8 @@ class SysLogHandler(logging.Handler):
LOG_NEWS = 7 # network news subsystem
LOG_UUCP = 8 # UUCP subsystem
LOG_CRON = 9 # clock daemon
- LOG_AUTHPRIV = 10 # security/authorization messages (private)
+ LOG_AUTHPRIV = 10 # security/authorization messages (private)
+ LOG_FTP = 11 # FTP daemon
# other codes through 15 reserved for system use
LOG_LOCAL0 = 16 # reserved for local use
@@ -665,6 +666,7 @@ class SysLogHandler(logging.Handler):
"authpriv": LOG_AUTHPRIV,
"cron": LOG_CRON,
"daemon": LOG_DAEMON,
+ "ftp": LOG_FTP,
"kern": LOG_KERN,
"lpr": LOG_LPR,
"mail": LOG_MAIL,