Commit graph

507 commits

Author SHA1 Message Date
Vinay Sajip 8a77f59de5
bpo-45628: Check all parts of the suffix for an extension match. (GH-29310) 2021-10-29 14:40:37 +01:00
Vinay Sajip 62a667784b
bpo-45401: Change shouldRollover() methods to only rollover regular f… (GH-28822)
…iles.

Also changed some historical return values from 1 -> True and 0 -> False.
2021-10-10 08:15:24 -07:00
Kirill Pinchuk 3d315c3116
bpo-44291: Fix reconnection in logging.handlers.SysLogHandler (GH-26490) 2021-08-05 14:58:16 +01:00
Vinay Sajip 6ff8903809
bpo-44753: Don't use logfile extension when determining old files to be deleted (GH-27475) 2021-07-30 12:48:50 +01:00
Mariusz Felisiak 11749e2dc2
bpo-44740: Lowercase "internet" and "web" where appropriate. (#27378)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-07-27 00:11:55 +02:00
andrei kulakov 96cf5a63d2
bpo-42378: fixed log truncation on logging shutdown (GH-27310)
Automerge-Triggered-By: GH:vsajip
2021-07-25 13:17:47 -07:00
Vinay Sajip 3b8075f907
bpo-44473: Update docstring and documentation for QueueHandler.prepar… (GH-27140)
…e().
2021-07-14 17:06:48 -07:00
andrei kulakov 8b93f0e696
bpo-43858: Add logging.getLevelNamesMapping() (GH-26459)
Added a function that returns a copy of a dict of logging levels.
2021-06-03 01:12:59 -07:00
Yonatan Goldschmidt 156699bca0
bpo-44222: Improve _removeHandlerRef() for a very long _handlerList (GH-26325)
The list lookups become a big burden for very long lists.
This patch changes the "happy flow" path of 2 lookups into 1 lookup.

Automerge-Triggered-By: GH:vsajip
2021-05-25 15:40:23 -07:00
Inada Naoki c2b7a66b91
bpo-43731: Add an encoding parameter to logging.fileConfig() (GH-25273) 2021-04-13 18:17:03 +09:00
Inada Naoki fb78692f2a
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25189)
* Fix _sitebuiltins
* Fix test_inspect
* Fix test_interpreters
* Fix test_io
* Fix test_iter
* Fix test_json
* Fix test_linecache
* Fix test_lltrace
* Fix test_logging
* Fix logging
2021-04-06 11:18:41 +09:00
Mariusz Felisiak bbba28212c
bpo-43353: Document that logging.getLevelName() accepts string representation of logging level. (GH-24693)
[bpo-43353]()

Automerge-Triggered-By: GH:vsajip
2021-03-08 03:16:20 -08:00
Matthias Bussonnier b32d8b4f9b
bpo-42644: Validate values in logging.disable() (#23786)
* bpo-42644: Validate values in logging.disable()

Technically make the value of manager a property that checks and convert
values assigned to it properly. This has the side effect of making
`logging.disable` also accept strings representing the various level of
warnings.

We want to validate the type of the disable attribute at assignment
time, as it is later compared to other levels when emitting warnings and
would generate a `TypeError: '>=' not supported between ....` in a
different part of the code base, which can make it difficult to track
down.

When assigned an incorrect value; it will raise a TypeError when the
wrong type, or ValueError if an invalid str.

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2020-12-16 11:43:39 +02:00
Victor Stinner 45df61fd2d
bpo-26789: Fix logging.FileHandler._open() at exit (GH-23053)
The logging.FileHandler class now keeps a reference to the builtin
open() function to be able to open or reopen the file during Python
finalization.

Fix errors like:

    Exception ignored in: (...)
    Traceback (most recent call last):
      (...)
      File ".../logging/__init__.py", line 1463, in error
      File ".../logging/__init__.py", line 1577, in _log
      File ".../logging/__init__.py", line 1587, in handle
      File ".../logging/__init__.py", line 1649, in callHandlers
      File ".../logging/__init__.py", line 948, in handle
      File ".../logging/__init__.py", line 1182, in emit
      File ".../logging/__init__.py", line 1171, in _open
    NameError: name 'open' is not defined
2020-11-02 23:17:46 +01:00
Necdet Can Atesman e9959c7118
bpo-42011: Update documentation of logging.Filter.filter() (GH-22692) 2020-10-16 15:14:07 +01:00
Hansraj Das a619af43cc
Delete extra 'the' from Formatter class docstring (GH-22530) 2020-10-04 17:09:26 +01:00
Eric Larson 9fdb76c34c
Fix logging error message (GH-22410)
Same changes as #22276 squashed to a single commit. Just hoping to get Travis to cooperate by opening a new PR...

Automerge-Triggered-By: @vsajip
2020-09-25 11:08:50 -07:00
Irit Katriel 2353d77fad
bpo-41503: Fix race between setTarget and flush in logging.handlers.MemoryHandler (GH-21765) 2020-08-16 16:10:13 +01:00
Bar Harel 8f192d12af
bpo-40884: Added defaults parameter for logging.Formatter (GH-20668)
Docs and tests are underway.

Automerge-Triggered-By: @vsajip
2020-06-18 07:18:58 -07:00
Rémi Lapeyre 25f38d7044
bpo-40836: Add docstring to logging.fatal() and logging.Logger.fatal() (GH-20563)
Automerge-Triggered-By: @vsajip
2020-06-15 01:03:07 -07:00
Arturo Escaip 8ad052464a
bpo-40756: Default second argument of LoggerAdapter.__init__ to None (GH-20362)
The 'extra' argument is not always used by custom logger adapters. For
example:

```python
class IndentAdapter(logging.LoggerAdapter):
    def process(self, msg, kwargs):
        indent = kwargs.pop(indent, 1)
        return ' ' * indent + msg, kwargs
```

It is cleaner and friendlier to default the 'extra' argument to None
instead of either forcing the subclasses of LoggerAdapter to pass a None
value directly or to override the constructor.

This change is backward compatible because existing calls to
`LoggerAdapter.__init__` are already passing a value for the second
argument.

Automerge-Triggered-By: @vsajip
2020-05-26 07:55:21 -07:00
Mariusz Felisiak 06a35542aa
bpo-40300: Allow empty logging.Formatter.default_msec_format. (GH-19551) 2020-04-17 17:02:47 +01:00
Victor Stinner 4c3da783cf
bpo-40091: Fix a hang at fork in the logging module (GH-19416)
Fix a hang at fork in the logging module: the new private
_at_fork_reinit() method is now used to reinitialize locks at fork in
the child process.

The createLock() method is no longer used at fork.
2020-04-14 00:25:34 +02:00
l0rb 22a9a546ff
bpo-39826: add getConnection() hook to logging HTTPHandler (GH-18745) 2020-03-04 10:49:51 +00:00
Vinay Sajip ce54519aa0
bpo-39292: Add missing syslog facility codes. (GH-17945) 2020-01-10 19:37:48 +00:00
Derek Brown 950c6795aa bpo-39198: Ensure logging global lock is released on exception in isEnabledFor (GH-17689) 2020-01-07 16:40:23 +00:00
Vinay Sajip 46abfc1416
bpo-39142: Avoid converting namedtuple instances to ConvertingTuple. (GH-17773)
This uses the heuristic of assuming a named tuple is a subclass of
tuple with a _fields attribute. This change means that contents of
a named tuple wouldn't be converted - if a user wants to have
ConvertingTuple functionality from a namedtuple, they will have to
implement it themselves.
2020-01-01 19:32:11 +00:00
Daniel Andersson d89cea15ad bpo-38781: Clear buffer in MemoryHandler flush (GH-17132)
This makes it easier to use a custom buffer when subclassing
MemoryHandler (by avoiding the explicity empty list literal
assignment in the flush method). For example, collection.deque
can now be used without any modifications to MemoryHandler.flush.

The same applies to BufferingHandler.
2019-11-13 09:03:45 +00:00
l0rb 519cb8772a bpo-38716: stop rotating handlers from setting inherited namer and rotator to None (GH-17072) 2019-11-06 21:21:40 +00:00
Lucas Cimon b15100fe7d bpo-38586: setting logging.Handler .name property in fileConfig (GH-16918) 2019-10-31 08:06:25 +00:00
Vinay Sajip 1d094af716
Updated incorrect level-setting code to use setLevel(). (GH-16325) 2019-09-22 03:51:51 +01:00
Vinay Sajip cb65b3a4f4
bpo-37742: Return the root logger when logging.getLogger('root') is c… (#15077)
* bpo-37742: Return the root logger when logging.getLogger('root') is called.

* Added type check guard on logger name in logging.getLogger() and refined a test.
2019-08-02 16:53:00 +01:00
Vinay Sajip ca7b504a4d
bpo-37111: Add 'encoding' and 'errors' parameters to logging.basicCon… (GH-14008) 2019-06-17 17:40:52 +01:00
Boris Feld 800d786370 Fix extraneous whitespace in QueueListener.prepare (GH-13803) 2019-06-04 16:20:17 +01:00
Bar Harel 6b282e1887 bpo-36813: Fix QueueListener to call task_done() upon termination. (GH-13113)
Fixed QueueListener in order to avoid random deadlocks.
Unable to add regression tests atm due to time constraints, will add it in a bit.
Regarding implementation, although it's nested, it does not cause performance issues whatsoever, and does not call task_done() in case of an exception (which is the right thing to do IMHO).


https://bugs.python.org/issue36813
2019-06-01 02:19:09 -07:00
Riccardo Magliocchetti ca87eebb22 bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908) 2019-05-07 22:36:39 +01:00
Gregory P. Smith 64aa6d2000
bpo-36533: Reinit logging.Handler locks on fork(). (GH-12704)
Instead of attempting to acquire and release them all across fork
which was leading to deadlocks in some applications that had chained
their own handlers while holding multiple locks.
2019-05-07 12:18:20 -04:00
Serhiy Storchaka 96aeaec647
bpo-36793: Remove unneeded __str__ definitions. (GH-13081)
Classes that define __str__ the same as __repr__ can
just inherit it from object.
2019-05-06 22:29:40 +03:00
Rémi Lapeyre 65f64b1903 bpo-36272: Logging now propagates RecursionError (GH-12312) 2019-03-15 06:53:34 +00:00
Manjusaka da6424e96a bpo-35726: Prevented QueueHandler formatting from affecting other handlers (GH-11537)
QueueHandler.prepare() now makes a copy of the record before modifying and enqueueing it, to avoid affecting other handlers in the chain.
2019-01-23 07:08:38 +00:00
Josh Snyder b7d62050e7 bpo-35046: do only one system call per line (logging.StreamHandler) (GH-10042) 2018-10-23 07:48:38 +01:00
BNMetrics 18fb1fb943 bpo-34844: logging.Formatter enhancement - Ensure style and format string matches in logging.Formatter (GH-9703) 2018-10-15 19:41:36 +01:00
Cheryl Sabella d345bb4d9b bpo-34334: Don't log traceback twice in QueueHandler (GH-9537) 2018-09-26 00:00:08 +01:00
Gregory P. Smith 19003841e9
bpo-6721: Hold logging locks across fork() (GH-4071)
bpo-6721: When os.fork() was called while another thread holds a logging lock, the child process may deadlock when it tries to log.  This fixes that by acquiring all logging locks before fork and releasing them afterwards.

A regression test that fails before this change is included.

Within the new unittest itself: There is a small _potential_ due to mixing of fork and a thread in the child process if the parent's thread happened to hold a non-reentrant library call lock (malloc?) when the os.fork() happens.  buildbots and time will tell if this actually manifests itself in this test or not.  :/  A functionality test that avoids that would be a challenge.

An alternate test that isn't trying to produce the deadlock itself but just checking that the release and acquire calls are made would be the next best alternative if so.
2018-09-13 22:08:31 -07:00
Vinay Sajip d3d3171da8
bpo-34415: Updated logging.Formatter docstring. (GH-8811) 2018-08-19 05:14:19 +01:00
Xtreak 087570af6d bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008) 2018-07-02 09:57:46 +01:00
Dong-hee Na cf67d6a934 bpo-33897: Add a 'force' keyword argument to logging.basicConfig(). (GH-7873) 2018-06-25 05:11:09 +01:00
Vinay Sajip dde9fdbe45
bpo-33165: Added stacklevel parameter to logging APIs. (GH-7424) 2018-06-05 17:24:18 +01:00
Timo Furrer 6e3ca645e7 bpo-33606: improve logging performance when logger is disabled (GH-7285)
A check has been added in Logger.isEnabledFor() to return False when the logger is disabled. This avoids unnecessary work being done when a disabled logger is used.
2018-06-01 08:29:46 +01:00
Vinay Sajip c4994dc00d
bpo-33400: Clarified documentation to indicate no strict adherence to ISO 8601. (GH-6702) 2018-05-04 22:20:54 +01:00
Serhiy Storchaka 3f2e6f15d6
Revert unneccessary changes made in bpo-30296 and apply other improvements. (GH-2624) 2018-02-26 16:50:11 +02:00
Vinay Sajip e96ba183c4
bpo-30904: Removed duplicated Host: header. (#4465) 2017-11-19 18:36:17 +00:00
sanjayp 2ae4ad7ca4 Changed lambda to str.strip in _strip_spaces in logging.config (#4332) 2017-11-15 09:28:11 +00:00
Lovesh Harchandani afad147b59 bpo-30989: Sort in TimedRotatingFileHandler only when needed. (GH-2812)
TimedRotatingFileHandler.getFilesToDelete() now sorts only when needed.
2017-10-27 08:04:33 +01:00
Łukasz Langa ce9e625445 bpo-31457: Don't omit inner `process()` calls with nested LogAdapters (#4044)
This used to be the case on Python 2.  Commit
212b590e11 changed the implementation for Python
3, making the `log()` method of LogAdapter call `logger._log()` directly.  This
makes nested log adapters not execute their ``process()`` method.  This patch
fixes the issue.

Also, now proxying `name`, too, to make `repr()` work with nested log adapters.

New tests added.
2017-10-19 10:24:55 -07:00
Łukasz Langa 0b6a118a45 bpo-31457: Make the LoggerAdapter.manager property settable (#4042)
Due to a bug in the initial fix, the setter was in fact creating a different
property.  This is now fixed.
2017-10-18 17:28:51 -07:00
Łukasz Langa 1bbd482bcf bpo-31457: Allow for nested LoggerAdapter objects (#3551)
Some of the proxied methods use internal Logger state which isn't proxied,
causing failures if an adapter is applied to another adapter.

This commit fixes the issue, adds a new test for the use case.
2017-09-14 11:34:47 -04:00
Victor Stinner 97d7e65dfe bpo-30830: logging.config.listen() calls server_close() (#3524)
The ConfigSocketReceiver.serve_until_stopped() method from
logging.config.listen() now calls server_close() (of
socketserver.ThreadingTCPServer) rather than closing manually the
socket.

While this change has no effect yet, it will help to prevent dangling
threads once ThreadingTCPServer.server_close() will join spawned
threads (bpo-31233).
2017-09-13 01:44:08 -07:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Preston Landers 6ea56d2ebc bpo-31080: Allowed logging.config.fileConfig() to accept both args and kwargs. (GH-2979) 2017-08-02 21:44:28 +01:00
favll adfe3440f6 bpo-31084: QueueHandler now formats messages correctly. (GH-2954) 2017-08-01 19:12:26 +01:00
Vinay Sajip 75f0b5dbac Updated LoggerAdapter.isEnabledFor to take advantage of caching. (GH-2951) 2017-07-30 20:15:18 +01:00
Vinay Sajip 2543f50033 bpo-30522: Implemented a method to allow setting a logging.StreamHander's stream. (GH-2921) 2017-07-30 10:41:45 +01:00
Avram Lubkin 78c18a9b9a bpo-30962: Added caching to Logger.isEnabledFor() (GH-2752) 2017-07-30 10:36:33 +01:00
Vinay Sajip 6260d9f203 bpo-30520: Implemented pickling for loggers. (#1956)
Implemented pickling for loggers.
2017-06-06 16:34:29 +01:00
Xiang Zhang 0b4b57df96 bpo-30378: Fix the problem that SysLogHandler can't handle IPv6 addresses (#1676) 2017-06-01 21:11:56 +08:00
Jon Dufresne 3972628de3 bpo-30296 Remove unnecessary tuples, lists, sets, and dicts (#1489)
* Replaced list(<generator expression>) with list comprehension
* Replaced dict(<generator expression>) with dict comprehension
* Replaced set(<list literal>) with set literal
* Replaced builtin func(<list comprehension>) with func(<generator
  expression>) when supported (e.g. any(), all(), tuple(), min(), &
  max())
2017-05-18 07:35:54 -07:00
Serhiy Storchaka 2e576f5aec bpo-30144: Import collections ABC from collections.abc rather than collections. (#1263) 2017-04-24 09:05:00 +03:00
Коренберг Марк 1b038e0738 bpo-29808: SysLogHandler: Do not fail if initial connect to syslog failed (#663) (#663) 2017-03-17 15:25:05 +00:00
Vinay Sajip d4f5001bac Issue #29220: Merged fixes from 3.6. 2017-01-11 17:44:07 +00:00
Vinay Sajip a861d48817 Issue #292Merged fixes from 3.5. 2017-01-11 17:41:28 +00:00
Vinay Sajip 924aaae4c2 Issue #29220: Improved fix and test. 2017-01-11 17:35:36 +00:00
Vinay Sajip 8b866d5429 Closes #29220: Fixed regression in logging.getLevelName(). 2017-01-11 06:57:55 +00:00
Vinay Sajip d489ac9102 Closes #28524: added default level for logging.disable(). 2016-12-31 11:40:11 +00:00
Vinay Sajip b74034351f Issue #28335: made minor improvement to implementation. 2016-10-03 19:50:56 +01:00
Vinay Sajip aa27582f35 Closes #28335: used 'raise from' in logging configuration code. 2016-10-03 19:45:50 +01:00
Vinay Sajip d61910c598 Fixes #27930: improved QueueListener behaviour. 2016-09-08 01:13:39 +01:00
Vinay Sajip ab7b0a03b5 Fixes #27937: optimise code used in all logging calls. 2016-09-03 16:50:09 +01:00
Vinay Sajip 93e6b3314d Closes #27930: Merged fix from 3.5. 2016-09-08 01:24:12 +01:00
Vinay Sajip 2500c98278 Closes #27935: returned numeric value for 'FATAL' logging level. 2016-09-03 17:04:36 +01:00
Vinay Sajip 0a7b7e30ff Fixes #27937: optimise code used in all logging calls. 2016-09-03 15:56:07 +01:00
Vinay Sajip c075201147 Closes #27650: Implemented repr methods for logging objects. 2016-08-06 10:28:31 +01:00
Vinay Sajip 638e622055 Closes #27493: accepted Path objects in file handlers for logging. 2016-07-22 18:23:04 +01:00
Vinay Sajip cccf6068fa Closes #26559: Allow configuring flush-on-close behaviour of MemoryHandler. 2016-07-22 16:27:31 +01:00
Vinay Sajip 24a72ca239 Fixed #27251: merged fix from 3.5. 2016-06-07 21:20:39 +01:00
Vinay Sajip 1bf197eb14 Fixed #27251: corrected string/bytes handling in credentials. 2016-06-07 21:19:55 +01:00
Georg Brandl 6d6dd73aec merge with 3.5 2016-02-25 20:18:00 +01:00
Georg Brandl 8c16cb9f65 Closes #26435: fix syntax in directives. Thanks to Jakub Stasiak. 2016-02-25 20:17:45 +01:00
Vinay Sajip c1681674d4 Closes #25685: Merged fix from 3.5. 2015-12-26 12:51:43 +00:00
Vinay Sajip 9cdfd18fc6 Closes #25685: Made SocketHandler emission more efficient. 2015-12-26 12:48:44 +00:00
Martin Panter 19e69c5a20 Issue #23883: Add missing APIs to __all__; patch by Jacek Kołodziej 2015-11-14 12:46:42 +00:00
Vinay Sajip 03de71d136 Closes #25411: Merged fix from 3.5. 2015-10-17 16:24:23 +01:00
Vinay Sajip 3f445f799a Closes #25411: Merged fix from 3.4. 2015-10-17 16:17:52 +01:00
Vinay Sajip 277640af0f Closes #25411: Improved Unicode support in SMTPHandler. 2015-10-17 16:13:10 +01:00
Vinay Sajip 29a1445136 Closes #24884: refactored WatchedFileHandler file reopening into a separate method, based on a suggestion and patch by Marian Horban. 2015-10-01 20:54:41 +01:00
Serhiy Storchaka 7e7a3dba5f Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released
even if errors are occured.
2015-04-10 13:24:41 +03:00
Serhiy Storchaka 2116b12da5 Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released
even if errors are occured.
2015-04-10 13:29:28 +03:00
Vinay Sajip 3505bd82a9 Issue #23207: merged fix from 3.4. 2015-03-18 08:49:57 +00:00
Vinay Sajip d55436ace3 Issue #23207: Improved kwarg validation. 2015-03-18 08:47:58 +00:00
Vinay Sajip 365701add9 Added respect_handler_level to QueueListener. 2015-02-09 19:49:00 +00:00