Commit Graph

448 Commits

Author SHA1 Message Date
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