From b4cb9930b91efd62b2f370c681dde9a08dd25d9c Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 26 Feb 2011 14:15:48 +0000 Subject: Issue #11330: asctime format bug fixed. --- Lib/logging/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index e1c4a37b53..d61699e035 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -360,12 +360,13 @@ class PercentStyle(object): default_format = '%(message)s' asctime_format = '%(asctime)s' + asctime_search = '%(asctime)' def __init__(self, fmt): self._fmt = fmt or self.default_format def usesTime(self): - return self._fmt.find(self.asctime_format) >= 0 + return self._fmt.find(self.asctime_search) >= 0 def format(self, record): return self._fmt % record.__dict__ @@ -373,6 +374,7 @@ class PercentStyle(object): class StrFormatStyle(PercentStyle): default_format = '{message}' asctime_format = '{asctime}' + asctime_search = '{asctime' def format(self, record): return self._fmt.format(**record.__dict__) @@ -381,6 +383,7 @@ class StrFormatStyle(PercentStyle): class StringTemplateStyle(PercentStyle): default_format = '${message}' asctime_format = '${asctime}' + asctime_search = '{asctime' def __init__(self, fmt): self._fmt = fmt or self.default_format -- cgit v1.2.1 From 345f8b5370b923a7e836dc7b5524c425b696e436 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 26 Feb 2011 14:28:36 +0000 Subject: Removed typo. --- Lib/logging/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index d61699e035..da12a0eb10 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -383,7 +383,7 @@ class StrFormatStyle(PercentStyle): class StringTemplateStyle(PercentStyle): default_format = '${message}' asctime_format = '${asctime}' - asctime_search = '{asctime' + asctime_search = '${asctime' def __init__(self, fmt): self._fmt = fmt or self.default_format -- cgit v1.2.1 From f5342ec47e772b3add2433cb16f51fe59e32f289 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 26 Feb 2011 16:06:02 +0000 Subject: Issue #11330: Updated tests for correct asctime handling. --- Lib/logging/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index da12a0eb10..d9ac7d9c13 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -383,7 +383,7 @@ class StrFormatStyle(PercentStyle): class StringTemplateStyle(PercentStyle): default_format = '${message}' asctime_format = '${asctime}' - asctime_search = '${asctime' + asctime_search = '${asctime}' def __init__(self, fmt): self._fmt = fmt or self.default_format -- cgit v1.2.1 From b060e73d63beffd242cea5dc9cd23253c452526b Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 29 Mar 2011 17:20:34 +0100 Subject: Closes issue #11557: Added Natalia Bidart's patch to improve test coverage. --- Lib/logging/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index e4b34a1af7..7757a824c7 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2011 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -18,7 +18,7 @@ Logging package for Python. Based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. -Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2011 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! """ @@ -1826,10 +1826,10 @@ class NullHandler(Handler): package. """ def handle(self, record): - pass + """Stub.""" def emit(self, record): - pass + """Stub.""" def createLock(self): self.lock = None -- cgit v1.2.1 From 9c5d6a1b28b5b6eabaede52a31fc42c34599613d Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 11 Apr 2011 08:42:07 +0100 Subject: Added 'handlers' argument to logging.basicConfig. --- Lib/logging/__init__.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 7757a824c7..ef88d0a0ed 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1650,6 +1650,10 @@ def basicConfig(**kwargs): stream Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with 'filename' - if both are present, 'stream' is ignored. + handlers If specified, this should be an iterable of already created + handlers, which will be added to the root handler. Any handler + in the list which does not have a formatter assigned will be + assigned the formatter created in this function. Note that you could specify a stream created using open(filename, mode) rather than passing the filename and mode in. However, it should be @@ -1657,27 +1661,47 @@ def basicConfig(**kwargs): using sys.stdout or sys.stderr), whereas FileHandler closes its stream when the handler is closed. - .. versionchanged: 3.2 + .. versionchanged:: 3.2 Added the ``style`` parameter. + + .. versionchanged:: 3.3 + Added the ``handlers`` parameter. A ``ValueError`` is now thrown for + incompatible arguments (e.g. ``handlers`` specified together with + ``filename``/``filemode``, or ``filename``/``filemode`` specified + together with ``stream``, or ``handlers`` specified together with + ``stream``. """ # Add thread safety in case someone mistakenly calls # basicConfig() from multiple threads _acquireLock() try: if len(root.handlers) == 0: - filename = kwargs.get("filename") - if filename: - mode = kwargs.get("filemode", 'a') - hdlr = FileHandler(filename, mode) + handlers = kwargs.get("handlers") + if handlers is None: + if "stream" in kwargs and "filename" in kwargs: + raise ValueError("'stream' and 'filename' should not be " + "specified together") else: - stream = kwargs.get("stream") - hdlr = StreamHandler(stream) + if "stream" in kwargs or "filename" in kwargs: + raise ValueError("'stream' or 'filename' should not be " + "specified together with 'handlers'") + if handlers is None: + filename = kwargs.get("filename") + if filename: + mode = kwargs.get("filemode", 'a') + h = FileHandler(filename, mode) + else: + stream = kwargs.get("stream") + h = StreamHandler(stream) + handlers = [h] fs = kwargs.get("format", BASIC_FORMAT) dfs = kwargs.get("datefmt", None) style = kwargs.get("style", '%') fmt = Formatter(fs, dfs, style) - hdlr.setFormatter(fmt) - root.addHandler(hdlr) + for h in handlers: + if h.formatter is None: + h.setFormatter(fmt) + root.addHandler(h) level = kwargs.get("level") if level is not None: root.setLevel(level) -- cgit v1.2.1 From 5ddfedc27a3c9a97115cce5799aa9507fd6e25fe Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 11 Apr 2011 08:43:52 +0100 Subject: Whitespace normalized. --- Lib/logging/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index ef88d0a0ed..8f4fc2b02d 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1663,7 +1663,7 @@ def basicConfig(**kwargs): .. versionchanged:: 3.2 Added the ``style`` parameter. - + .. versionchanged:: 3.3 Added the ``handlers`` parameter. A ``ValueError`` is now thrown for incompatible arguments (e.g. ``handlers`` specified together with -- cgit v1.2.1 From 49fcc4a293cbbc0c5944af165aec6064811eada3 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 26 Apr 2011 18:43:05 +0100 Subject: test_logging coverage improvements. --- Lib/logging/__init__.py | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 8f4fc2b02d..eb1f934acc 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -37,13 +37,13 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR', try: import codecs -except ImportError: +except ImportError: #pragma: no cover codecs = None try: import _thread as thread import threading -except ImportError: +except ImportError: #pragma: no cover thread = None __author__ = "Vinay Sajip " @@ -67,16 +67,16 @@ else: _srcfile = __file__ _srcfile = os.path.normcase(_srcfile) -# next bit filched from 1.5.2's inspect.py -def currentframe(): - """Return the frame object for the caller's stack frame.""" - try: - raise Exception - except: - return sys.exc_info()[2].tb_frame.f_back -if hasattr(sys, '_getframe'): currentframe = lambda: sys._getframe(3) -# done filching +if hasattr(sys, '_getframe'): + currentframe = lambda: sys._getframe(3) +else: #pragma: no cover + def currentframe(): + """Return the frame object for the caller's stack frame.""" + try: + raise Exception + except: + return sys.exc_info()[2].tb_frame.f_back # _srcfile is only used in conjunction with sys._getframe(). # To provide compatibility with older versions of Python, set _srcfile @@ -94,22 +94,22 @@ _startTime = time.time() #raiseExceptions is used to see if exceptions during handling should be #propagated # -raiseExceptions = 1 +raiseExceptions = True # # If you don't want threading information in the log, set this to zero # -logThreads = 1 +logThreads = True # # If you don't want multiprocessing information in the log, set this to zero # -logMultiprocessing = 1 +logMultiprocessing = True # # If you don't want process information in the log, set this to zero # -logProcesses = 1 +logProcesses = True #--------------------------------------------------------------------------- # Level related stuff @@ -201,7 +201,7 @@ def _checkLevel(level): # if thread: _lock = threading.RLock() -else: +else: #pragma: no cover _lock = None @@ -281,10 +281,10 @@ class LogRecord(object): if logThreads and thread: self.thread = thread.get_ident() self.threadName = threading.current_thread().name - else: + else: # pragma: no cover self.thread = None self.threadName = None - if not logMultiprocessing: + if not logMultiprocessing: # pragma: no cover self.processName = None else: self.processName = 'MainProcess' @@ -644,11 +644,11 @@ class Filter(object): yes. If deemed appropriate, the record may be modified in-place. """ if self.nlen == 0: - return 1 + return True elif self.name == record.name: - return 1 + return True elif record.name.find(self.name, 0, self.nlen) != 0: - return 0 + return False return (record.name[self.nlen] == ".") class Filterer(object): @@ -775,7 +775,7 @@ class Handler(Filterer): """ if thread: self.lock = threading.RLock() - else: + else: #pragma: no cover self.lock = None def acquire(self): @@ -939,7 +939,7 @@ class StreamHandler(Handler): stream.write(msg) stream.write(self.terminator) self.flush() - except (KeyboardInterrupt, SystemExit): + except (KeyboardInterrupt, SystemExit): #pragma: no cover raise except: self.handleError(record) @@ -948,13 +948,13 @@ class FileHandler(StreamHandler): """ A handler class which writes formatted logging records to disk files. """ - def __init__(self, filename, mode='a', encoding=None, delay=0): + def __init__(self, filename, mode='a', encoding=None, delay=False): """ Open the specified file and use it as the stream for logging. """ #keep the absolute path, otherwise derived classes which use this #may come a cropper when the current directory changes - if codecs is None: + if codecs is None: #pragma: no cover encoding = None self.baseFilename = os.path.abspath(filename) self.mode = mode @@ -1352,9 +1352,9 @@ class Logger(Filterer): #IronPython can use logging. try: fn, lno, func, sinfo = self.findCaller(stack_info) - except ValueError: + except ValueError: # pragma: no cover fn, lno, func = "(unknown file)", 0, "(unknown function)" - else: + else: # pragma: no cover fn, lno, func = "(unknown file)", 0, "(unknown function)" if exc_info: if not isinstance(exc_info, tuple): @@ -1465,7 +1465,7 @@ class Logger(Filterer): Is this logger enabled for level 'level'? """ if self.manager.disable >= level: - return 0 + return False return level >= self.getEffectiveLevel() def getChild(self, suffix): -- cgit v1.2.1 From 4fb0d089ffa6bbbeb362b96039a2bd510196a2a5 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 26 Apr 2011 19:34:04 +0100 Subject: More test_logging coverage improvements. --- Lib/logging/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index eb1f934acc..cd640bb495 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -890,7 +890,7 @@ class Handler(Filterer): None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) - except IOError: + except IOError: #pragma: no cover pass # see issue 5971 finally: del ei -- cgit v1.2.1 From 2ce150c796c024df9fb9bf1953fcd2ea140ff767 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 28 Apr 2011 12:04:58 +0100 Subject: Improved test_logging coverage. --- Lib/logging/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index cd640bb495..7f7d5c988b 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -296,7 +296,7 @@ class LogRecord(object): # for an example try: self.processName = mp.current_process().name - except StandardError: + except StandardError: #pragma: no cover pass if logProcesses and hasattr(os, 'getpid'): self.process = os.getpid() -- cgit v1.2.1 From 703d40cc4062622c7ae7c621c64893d12daad9ff Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 30 Apr 2011 21:51:51 +0100 Subject: Updated usage of boolean values. --- Lib/logging/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 7f7d5c988b..3a8a6391ec 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -688,14 +688,14 @@ class Filterer(object): Allow filters to be just callables. """ - rv = 1 + rv = True for f in self.filters: if hasattr(f, 'filter'): result = f.filter(record) else: result = f(record) # assume callable - will raise if not if not result: - rv = 0 + rv = False break return rv @@ -1197,9 +1197,9 @@ class Logger(Filterer): self.name = name self.level = _checkLevel(level) self.parent = None - self.propagate = 1 + self.propagate = True self.handlers = [] - self.disabled = 0 + self.disabled = False def setLevel(self, level): """ @@ -1567,7 +1567,7 @@ class LoggerAdapter(object): """ Delegate an exception call to the underlying logger. """ - kwargs["exc_info"] = 1 + kwargs["exc_info"] = True self.log(ERROR, msg, *args, **kwargs) def critical(self, msg, *args, **kwargs): -- cgit v1.2.1 From 2ccd281bc2741b0fe14884c8d6ae1bf76bbb6847 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 30 May 2011 23:02:52 +0200 Subject: Close #12028: Make threading._get_ident() public, rename it to threading.get_ident() and document it. This function was used by _thread.get_ident(). --- Lib/logging/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 3a8a6391ec..1a4b241226 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -41,10 +41,9 @@ except ImportError: #pragma: no cover codecs = None try: - import _thread as thread import threading except ImportError: #pragma: no cover - thread = None + threading = None __author__ = "Vinay Sajip " __status__ = "production" @@ -199,7 +198,7 @@ def _checkLevel(level): #the lock would already have been acquired - so we need an RLock. #The same argument applies to Loggers and Manager.loggerDict. # -if thread: +if threading: _lock = threading.RLock() else: #pragma: no cover _lock = None @@ -278,8 +277,8 @@ class LogRecord(object): self.created = ct self.msecs = (ct - int(ct)) * 1000 self.relativeCreated = (self.created - _startTime) * 1000 - if logThreads and thread: - self.thread = thread.get_ident() + if logThreads and threading: + self.thread = threading.get_ident() self.threadName = threading.current_thread().name else: # pragma: no cover self.thread = None @@ -773,7 +772,7 @@ class Handler(Filterer): """ Acquire a thread lock for serializing access to the underlying I/O. """ - if thread: + if threading: self.lock = threading.RLock() else: #pragma: no cover self.lock = None -- cgit v1.2.1 From 8d927c206d58b414d6cc5780e494fa9360fa59e8 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 9 Jun 2011 18:42:19 +0100 Subject: Made time formats in Formatter more configurable. --- Lib/logging/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 1a4b241226..509dae627b 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -467,6 +467,9 @@ class Formatter(object): self._fmt = self._style._fmt self.datefmt = datefmt + default_time_format = '%Y-%m-%d %H:%M:%S' + default_msec_format = '%s,%03d' + def formatTime(self, record, datefmt=None): """ Return the creation time of the specified LogRecord as formatted text. @@ -489,8 +492,8 @@ class Formatter(object): if datefmt: s = time.strftime(datefmt, ct) else: - t = time.strftime("%Y-%m-%d %H:%M:%S", ct) - s = "%s,%03d" % (t, record.msecs) # the use of % here is internal + t = time.strftime(self.default_time_format, ct) + s = self.default_msec_format % (t, record.msecs) return s def formatException(self, ei): -- cgit v1.2.1 From 5e1af43955083f243eb640e4e92fa2642ca4b668 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Fri, 21 Oct 2011 07:33:42 +0100 Subject: Closes #13235: Added deprecation for warn() methods and function in logging. --- Lib/logging/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 8406df3abd..6e0394fa35 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1243,7 +1243,10 @@ class Logger(Filterer): if self.isEnabledFor(WARNING): self._log(WARNING, msg, args, **kwargs) - warn = warning + def warn(self, msg, *args, **kwargs): + warnings.warn("The 'warn' method is deprecated, " + "use 'warning' instead", PendingDeprecationWarning, 2) + self.warning(msg, *args, **kwargs) def error(self, msg, *args, **kwargs): """ @@ -1556,7 +1559,10 @@ class LoggerAdapter(object): """ self.log(WARNING, msg, *args, **kwargs) - warn = warning + def warn(self, msg, *args, **kwargs): + warnings.warn("The 'warn' method is deprecated, " + "use 'warning' instead", PendingDeprecationWarning, 2) + self.warning(msg, *args, **kwargs) def error(self, msg, *args, **kwargs): """ @@ -1766,7 +1772,10 @@ def warning(msg, *args, **kwargs): basicConfig() root.warning(msg, *args, **kwargs) -warn = warning +def warn(msg, *args, **kwargs): + warnings.warn("The 'warn' function is deprecated, " + "use 'warning' instead", PendingDeprecationWarning, 2) + warning(msg, *args, **kwargs) def info(msg, *args, **kwargs): """ -- cgit v1.2.1 From 02221254e362996f15c647909ba42f5175b44e03 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 22 Oct 2011 13:34:48 +0100 Subject: Closes #13235: Changed PendingDeprecationWarning to DeprecationWarning. --- Lib/logging/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 6e0394fa35..abc4b0cbc2 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -251,7 +251,7 @@ class LogRecord(object): # during formatting, we test to see if the arg is present using # 'if self.args:'. If the event being logged is e.g. 'Value is %d' # and if the passed arg fails 'if self.args:' then no formatting - # is done. For example, logger.warn('Value is %d', 0) would log + # is done. For example, logger.warning('Value is %d', 0) would log # 'Value is %d' instead of 'Value is 0'. # For the use case of passing a dictionary, this should not be a # problem. @@ -1245,7 +1245,7 @@ class Logger(Filterer): def warn(self, msg, *args, **kwargs): warnings.warn("The 'warn' method is deprecated, " - "use 'warning' instead", PendingDeprecationWarning, 2) + "use 'warning' instead", DeprecationWarning, 2) self.warning(msg, *args, **kwargs) def error(self, msg, *args, **kwargs): @@ -1561,7 +1561,7 @@ class LoggerAdapter(object): def warn(self, msg, *args, **kwargs): warnings.warn("The 'warn' method is deprecated, " - "use 'warning' instead", PendingDeprecationWarning, 2) + "use 'warning' instead", DeprecationWarning, 2) self.warning(msg, *args, **kwargs) def error(self, msg, *args, **kwargs): @@ -1774,7 +1774,7 @@ def warning(msg, *args, **kwargs): def warn(msg, *args, **kwargs): warnings.warn("The 'warn' function is deprecated, " - "use 'warning' instead", PendingDeprecationWarning, 2) + "use 'warning' instead", DeprecationWarning, 2) warning(msg, *args, **kwargs) def info(msg, *args, **kwargs): -- cgit v1.2.1 From 5458423449945ddc2e8e57e10aaca157b8df5723 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Mon, 7 Nov 2011 19:43:05 +0100 Subject: logging: replace codecs.open with builtins.open, remove '_encoded' sort, add some tests. --- Lib/logging/__init__.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 988cbed61c..25acb3ffbe 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -35,11 +35,6 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR', 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'warn', 'warning', 'getLogRecordFactory', 'setLogRecordFactory', 'lastResort'] -try: - import codecs -except ImportError: #pragma: no cover - codecs = None - try: import threading except ImportError: #pragma: no cover @@ -954,8 +949,6 @@ class FileHandler(StreamHandler): """ #keep the absolute path, otherwise derived classes which use this #may come a cropper when the current directory changes - if codecs is None: #pragma: no cover - encoding = None self.baseFilename = os.path.abspath(filename) self.mode = mode self.encoding = encoding @@ -983,11 +976,7 @@ class FileHandler(StreamHandler): Open the current base file with the (original) mode and encoding. Return the resulting stream. """ - if self.encoding is None: - stream = open(self.baseFilename, self.mode) - else: - stream = codecs.open(self.baseFilename, self.mode, self.encoding) - return stream + return open(self.baseFilename, self.mode, encoding=self.encoding) def emit(self, record): """ -- cgit v1.2.1 From 819b53a7b00a0ccb532db2a0186cc15ca4adbebf Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 17 Dec 2011 12:36:34 -0800 Subject: Mention that level can be an int or str in the setLevel docstring. --- Lib/logging/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib/logging/__init__.py') diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 25acb3ffbe..3b2b9bf3b6 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -789,7 +789,7 @@ class Handler(Filterer): def setLevel(self, level): """ - Set the logging level of this handler. + Set the logging level of this handler. level must be an int or a str. """ self.level = _checkLevel(level) @@ -1194,7 +1194,7 @@ class Logger(Filterer): def setLevel(self, level): """ - Set the logging level of this logger. + Set the logging level of this logger. level must be an int or a str. """ self.level = _checkLevel(level) -- cgit v1.2.1