diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2016-08-06 09:28:31 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2016-08-06 09:28:31 (GMT) |
commit | c0752011472790e34d171b89f4b862cc3fd8ad08 (patch) | |
tree | 545d507278f6d9b4510ac5fcadf094ef51d621d5 /Lib/logging | |
parent | 933c66af56f315bca6f0f8b605db0831e3685d24 (diff) | |
download | cpython-c0752011472790e34d171b89f4b862cc3fd8ad08.zip cpython-c0752011472790e34d171b89f4b862cc3fd8ad08.tar.gz cpython-c0752011472790e34d171b89f4b862cc3fd8ad08.tar.bz2 |
Closes #27650: Implemented repr methods for logging objects.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index fd422ea..4d872bd 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -935,6 +935,10 @@ class Handler(Filterer): finally: del t, v, tb + def __repr__(self): + level = getLevelName(self.level) + return '<%s (%s)>' % (self.__class__.__name__, level) + class StreamHandler(Handler): """ A handler class which writes logging records, appropriately formatted, @@ -986,6 +990,14 @@ class StreamHandler(Handler): except Exception: self.handleError(record) + def __repr__(self): + level = getLevelName(self.level) + name = getattr(self.stream, 'name', '') + if name: + name += ' ' + return '<%s %s(%s)>' % (self.__class__.__name__, name, level) + + class FileHandler(StreamHandler): """ A handler class which writes formatted logging records to disk files. @@ -1050,6 +1062,11 @@ class FileHandler(StreamHandler): self.stream = self._open() StreamHandler.emit(self, record) + def __repr__(self): + level = getLevelName(self.level) + return '<%s %s (%s)>' % (self.__class__.__name__, self.baseFilename, level) + + class _StderrHandler(StreamHandler): """ This class is like a StreamHandler using sys.stderr, but always uses @@ -1542,6 +1559,11 @@ class Logger(Filterer): suffix = '.'.join((self.name, suffix)) return self.manager.getLogger(suffix) + def __repr__(self): + level = getLevelName(self.getEffectiveLevel()) + return '<%s %s (%s)>' % (self.__class__.__name__, self.name, level) + + class RootLogger(Logger): """ A root logger is not that different to any other logger, except that @@ -1668,6 +1690,11 @@ class LoggerAdapter(object): """ return self.logger.hasHandlers() + def __repr__(self): + logger = self.logger + level = getLevelName(logger.getEffectiveLevel()) + return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level) + root = RootLogger(WARNING) Logger.root = root Logger.manager = Manager(Logger.root) |