Skip to content

Commit a982eb8

Browse files
xrmxbasepi
andauthored
Deprecate Python < 3.2 logging code and and remove documentation (#1984)
* docs: remove Python < 3.2 specific documentation * handlers/logging: deprecate Python<3.2 LoggingFilter Since we don't support Python < 3.6 there's not reason to keep code for Python versions older than that. * Update elasticapm/handlers/logging.py Co-authored-by: Colton Myers <[email protected]> --------- Co-authored-by: Colton Myers <[email protected]>
1 parent 022080f commit a982eb8

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

docs/logging.asciidoc

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ as well as http://www.structlog.org/en/stable/[`structlog`].
3636
[[logging]]
3737
===== `logging`
3838

39-
For Python 3.2+, we use https://docs.python.org/3/library/logging.html#logging.setLogRecordFactory[`logging.setLogRecordFactory()`]
39+
We use https://docs.python.org/3/library/logging.html#logging.setLogRecordFactory[`logging.setLogRecordFactory()`]
4040
to decorate the default LogRecordFactory to automatically add new attributes to
4141
each LogRecord object:
4242

@@ -51,25 +51,6 @@ You can disable this automatic behavior by using the
5151
<<config-generic-disable-log-record-factory,`disable_log_record_factory`>> setting
5252
in your configuration.
5353

54-
For Python versions <3.2, we also provide a
55-
https://docs.python.org/3/library/logging.html#filter-objects[filter] which will
56-
add the same new attributes to any filtered `LogRecord`:
57-
58-
[source,python]
59-
----
60-
import logging
61-
from elasticapm.handlers.logging import LoggingFilter
62-
63-
console = logging.StreamHandler()
64-
console.addFilter(LoggingFilter())
65-
# add the handler to the root logger
66-
logging.getLogger("").addHandler(console)
67-
----
68-
69-
NOTE: Because https://docs.python.org/3/library/logging.html#filter-objects[filters
70-
are not propagated to descendent loggers], you should add the filter to each of
71-
your log handlers, as handlers are propagated, along with their attached filters.
72-
7354
[float]
7455
[[structlog]]
7556
===== `structlog`

elasticapm/handlers/logging.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ class LoggingFilter(logging.Filter):
194194
automatically.
195195
"""
196196

197+
def __init__(self, name=""):
198+
super().__init__(name=name)
199+
warnings.warn(
200+
"The LoggingFilter is deprecated and will be removed in v7.0 of "
201+
"the agent. On Python 3.2+, by default we add a LogRecordFactory to "
202+
"your root logger automatically"
203+
"https://www.elastic.co/guide/en/apm/agent/python/current/logs.html",
204+
PendingDeprecationWarning,
205+
)
206+
197207
def filter(self, record):
198208
"""
199209
Add elasticapm attributes to `record`.

0 commit comments

Comments
 (0)