Skip to content

Commit

Permalink
Deprecate Python < 3.2 logging code and and remove documentation (#1984)
Browse files Browse the repository at this point in the history
* 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 <colton@basepi.net>

---------

Co-authored-by: Colton Myers <colton@basepi.net>
  • Loading branch information
xrmx and basepi authored Mar 13, 2024
1 parent 022080f commit a982eb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
21 changes: 1 addition & 20 deletions docs/logging.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ as well as http://www.structlog.org/en/stable/[`structlog`].
[[logging]]
===== `logging`

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

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

For Python versions <3.2, we also provide a
https://docs.python.org/3/library/logging.html#filter-objects[filter] which will
add the same new attributes to any filtered `LogRecord`:

[source,python]
----
import logging
from elasticapm.handlers.logging import LoggingFilter
console = logging.StreamHandler()
console.addFilter(LoggingFilter())
# add the handler to the root logger
logging.getLogger("").addHandler(console)
----

NOTE: Because https://docs.python.org/3/library/logging.html#filter-objects[filters
are not propagated to descendent loggers], you should add the filter to each of
your log handlers, as handlers are propagated, along with their attached filters.

[float]
[[structlog]]
===== `structlog`
Expand Down
10 changes: 10 additions & 0 deletions elasticapm/handlers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ class LoggingFilter(logging.Filter):
automatically.
"""

def __init__(self, name=""):
super().__init__(name=name)
warnings.warn(
"The LoggingFilter is deprecated and will be removed in v7.0 of "
"the agent. On Python 3.2+, by default we add a LogRecordFactory to "
"your root logger automatically"
"https://www.elastic.co/guide/en/apm/agent/python/current/logs.html",
PendingDeprecationWarning,
)

def filter(self, record):
"""
Add elasticapm attributes to `record`.
Expand Down

0 comments on commit a982eb8

Please sign in to comment.