summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-10-19 15:26:24 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-10-19 15:26:24 (GMT)
commit062d56b1f04122cd631a1d0815d4505598a5183d (patch)
tree7caa69bec75de562fa7b1c02383390e04ac45f15
parent7cd94b8aa2bff16d06b254b697c62d52a3f6f5fa (diff)
downloadcpython-062d56b1f04122cd631a1d0815d4505598a5183d.zip
cpython-062d56b1f04122cd631a1d0815d4505598a5183d.tar.gz
cpython-062d56b1f04122cd631a1d0815d4505598a5183d.tar.bz2
logging: Added _logRecordClass, getLogRecordClass, setLogRecordClass to increase flexibility of LogRecord creation.
-rw-r--r--Lib/logging/__init__.py26
-rw-r--r--Misc/NEWS3
2 files changed, 26 insertions, 3 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index b9cea3f..0c6a186 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -31,7 +31,8 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'StreamHandler', 'WARN', 'WARNING', 'addLevelName', 'basicConfig',
'captureWarnings', 'critical', 'debug', 'disable', 'error',
'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass',
- 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'warn', 'warning']
+ 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'warn', 'warning',
+ 'getLogRecordClass', 'setLogRecordClass']
try:
import codecs
@@ -316,6 +317,25 @@ class LogRecord(object):
msg = msg % self.args
return msg
+#
+# Determine which class to use when instantiating log records.
+#
+_logRecordClass = LogRecord
+
+def setLogRecordClass(cls):
+ """
+ Set the class to be used when instantiating a log record.
+ """
+ global _logRecordClass
+ _logRecordClass = cls
+
+def getLogRecordClass():
+ """
+ Return the class to be used when instantiating a log record.
+ """
+
+ return _logRecordClass
+
def makeLogRecord(dict):
"""
Make a LogRecord whose attributes are defined by the specified dictionary,
@@ -323,7 +343,7 @@ def makeLogRecord(dict):
a socket connection (which is sent as a dictionary) into a LogRecord
instance.
"""
- rv = LogRecord(None, None, "", 0, "", (), None, None)
+ rv = _logRecordClass(None, None, "", 0, "", (), None, None)
rv.__dict__.update(dict)
return rv
@@ -1183,7 +1203,7 @@ class Logger(Filterer):
A factory method which can be overridden in subclasses to create
specialized LogRecords.
"""
- rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
+ rv = _logRecordClass(name, level, fn, lno, msg, args, exc_info, func)
if extra is not None:
for key in extra:
if (key in ["message", "asctime"]) or (key in rv.__dict__):
diff --git a/Misc/NEWS b/Misc/NEWS
index 2f030c3..4b92ef6 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@ Core and Builtins
Library
-------
+- logging: Added _logRecordClass, getLogRecordClass, setLogRecordClass to
+ increase flexibility of LogRecord creation.
+
- Issue #5117: Case normalization was needed on ntpath.relpath(). And
fixed root directory issue on posixpath.relpath(). (Ported working fixes
from ntpath)