From 9397a6df51a28bbc2479ef76c9ad6f6f2b4cfcea Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 4 Mar 2024 16:12:36 +0100 Subject: [PATCH 1/3] docs: remove Python < 3.2 specific documentation --- docs/logging.asciidoc | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/docs/logging.asciidoc b/docs/logging.asciidoc index 943de8f64..8f51edd50 100644 --- a/docs/logging.asciidoc +++ b/docs/logging.asciidoc @@ -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: @@ -51,25 +51,6 @@ You can disable this automatic behavior by using the <> 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` From 9f971d148cfc550fa8e3baad009fed05016f9fb8 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 4 Mar 2024 16:19:45 +0100 Subject: [PATCH 2/3] 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. --- elasticapm/handlers/logging.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/elasticapm/handlers/logging.py b/elasticapm/handlers/logging.py index 4407f0f87..f22ee6021 100644 --- a/elasticapm/handlers/logging.py +++ b/elasticapm/handlers/logging.py @@ -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 Rdd 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`. From b74cce8fb49d1f8345bd9bf07a179d4f8af20208 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 5 Mar 2024 09:27:07 +0100 Subject: [PATCH 3/3] Update elasticapm/handlers/logging.py Co-authored-by: Colton Myers --- elasticapm/handlers/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticapm/handlers/logging.py b/elasticapm/handlers/logging.py index f22ee6021..ed4db87ac 100644 --- a/elasticapm/handlers/logging.py +++ b/elasticapm/handlers/logging.py @@ -198,7 +198,7 @@ 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 Rdd a LogRecordFactory to " + "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,