This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 9c1884281f045c33892d44ebd3fce0cd8991ba51 Author: Piotr P. Karwasz <[email protected]> AuthorDate: Tue Jul 2 15:53:09 2024 +0200 Apply review for #2381 --- src/changelog/.3.x.x/2408_remove_log4j_kubernetes.xml | 11 ----------- .../examples/migrate-from-logback/MigrateFromLogback.java | 8 ++++---- src/site/antora/modules/ROOT/pages/migrate-from-logback.adoc | 9 +++++---- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/changelog/.3.x.x/2408_remove_log4j_kubernetes.xml b/src/changelog/.3.x.x/2408_remove_log4j_kubernetes.xml deleted file mode 100644 index 7bb23f64f6..0000000000 --- a/src/changelog/.3.x.x/2408_remove_log4j_kubernetes.xml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="https://logging.apache.org/xml/ns" - xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" - type="changed"> - <issue id="2408" link="https://github.com/apache/logging-log4j2/pull/2408"/> - <description format="asciidoc"> - Remove `log4j-kubernetes` lookup. - User should migrate to https://github.com/fabric8io/kubernetes-client/blob/main/doc/KubernetesLog4j.md[`kubernetes-log4j`] - </description> -</entry> diff --git a/src/site/antora/modules/ROOT/examples/migrate-from-logback/MigrateFromLogback.java b/src/site/antora/modules/ROOT/examples/migrate-from-logback/MigrateFromLogback.java index d9b1b2b8bb..de21dc4eed 100644 --- a/src/site/antora/modules/ROOT/examples/migrate-from-logback/MigrateFromLogback.java +++ b/src/site/antora/modules/ROOT/examples/migrate-from-logback/MigrateFromLogback.java @@ -26,8 +26,8 @@ class MigrateFromLogback { try { // do something // tag::wrong[] - } catch (Exception e) { - logger.error("The foo process exited with an error: {}", e); + } catch (Exception exception) { + logger.error("The foo process exited with an error: {}", exception); } // end::wrong[] } @@ -36,8 +36,8 @@ class MigrateFromLogback { try { // do something // tag::right[] - } catch (Exception e) { - logger.error("The foo process exited with an error.", e); + } catch (Exception exception) { + logger.error("The foo process exited with an error.", exception); } // end::right[] } diff --git a/src/site/antora/modules/ROOT/pages/migrate-from-logback.adoc b/src/site/antora/modules/ROOT/pages/migrate-from-logback.adoc index 79e8c9a1a8..bb03e2c77a 100644 --- a/src/site/antora/modules/ROOT/pages/migrate-from-logback.adoc +++ b/src/site/antora/modules/ROOT/pages/migrate-from-logback.adoc @@ -120,7 +120,7 @@ include::example$migrate-from-logback/MigrateFromLogback.java[tag=wrong] Log4j Core and Logback differ in the way they treat this statement: Logback:: -Logback interprets the `e` argument as throwable and removes it from the list of parameters. +Logback interprets the `exception` argument as throwable and removes it from the list of parameters. We end up with a parameterized statement with one placeholder, but zero parameters. The placeholder therefore remains as is: + @@ -134,7 +134,7 @@ java.lang.RuntimeException: Message Log4j Core:: Log4j Core first looks for the parameters of the message. -Since the format string has one placeholder, the `e` argument is interpreted as a parameter of the log message. +Since the format string has one placeholder, the `exception` argument is interpreted as a parameter of the log message. The throwable associated to the log event is `null`, which results in a missing stack trace: + [source] @@ -142,7 +142,7 @@ The throwable associated to the log event is `null`, which results in a missing The foo process exited with and error: java.lang.RuntimeException: Message ---- -To fix this problem and obtain the same output in both backends, you should remove the placeholder from the format string: +To fix this problem and get the same output in both backends, you should remove the placeholder from the format string: [source,java,indent=0] ---- @@ -164,4 +164,5 @@ java.lang.RuntimeException: Message As a temporary solution, the SLF4J-to-Log4j API bridges contain a special xref:manual/api.adoc#logger-message-factories[`MessageFactory`] that classifies trailing `Throwable` arguments in the same way Logback does. -To use it, you need to set the xref:manual/systemproperties.adoc#log4j2.messageFactory[`log4j2.messageFactory`] configuration property to `org.apache.logging.slf4j.message.ThrowableConsumingMessageFactory`. \ No newline at end of file +To use it, you need to set the xref:manual/systemproperties.adoc#log4j2.messageFactory[`log4j2.messageFactory`] configuration property to `org.apache.logging.slf4j.message.ThrowableConsumingMessageFactory`. +====
