Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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