You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "grobmeier (via GitHub)" <gi...@apache.org> on 2024/05/16 21:29:16 UTC

[PR] Rewrote Messages (logging-log4j2)

grobmeier opened a new pull request, #2591:
URL: https://github.com/apache/logging-log4j2/pull/2591

   Messages - draft, work in progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Rewrote Messages (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #2591:
URL: https://github.com/apache/logging-log4j2/pull/2591#discussion_r1612316217


##########
src/site/antora/modules/ROOT/pages/manual/messages.adoc:
##########
@@ -16,311 +16,361 @@
 ////
 = Messages
 
-Although Log4j 2 provides Logger methods that accept Strings and
-Objects, all of these are ultimately captured in Message objects that
-are then associated with the log event. Applications are free to
-construct Messages of their own and pass them to the Logger. Although it
-may seem more expensive than passing the message format and parameters
-directly to the event, testing has shown that with modern JVMs the cost
-of creating and destroying events is minor, especially when complex
-tasks are encapsulated in the Message instead of the application. In
-addition, when using the methods that accept Strings and parameters, the
-underlying Message object will only be created if any configured global
-filters or the Logger's log level allow the message to be processed.
-
-Consider an application that has a Map object containing \{"Name" =
-"John Doe", "Address" = "123 Main St.", "Phone" = "(999) 555-1212"} and
-a User object that has a getId method that returns "jdoe". The developer
-would like to add an informational message that returns "User John Doe
-has logged in using id jdoe". The way this could be accomplished is by
-doing:
-
-[source,java]
+Messages are a way to encapsulate the creation of logging statements.
+Developers can use them to make code more readable and reuseable.

Review Comment:
   I pushed the changes directly in this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Rewrote Messages (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #2591:
URL: https://github.com/apache/logging-log4j2/pull/2591#issuecomment-2116863768

   @grobmeier, I once started rewriting this, and back then drafted the following intro:
   
   ```
   Although Log4j provides `Logger` methods that accept a formatting pattern of type `String` and its parameters of type `Object`, all of these are ultimately captured in link:../javadoc/log4j-api/org/apache/logging/log4j/message/Message.html[`Message`] objects that are attached to the generated log event:
   
   [source,java]
   ----
   LOGGER.info("Everything is awesome!");
   LOGGER.info("Party time for `{}`", userName);
   ----
   
   is analogous to
   
   [source,java]
   ----
   LOGGER.info(new SimpleMessage("Everything is awesome!"));
   LOGGER.info(new ParameterizedMessage("Party time for `{}`", new Object[]{userId}));
   ----
   ```
   
   Here I like the way readers are demonstrated with how `LOGGER.foo(bar)` under-the-hood translates to `LOGGER.foo(new Message(bar))`. Maybe you can use this. :angel:
   
   **Caution:** _"is analogous to"_ phrase is important here, since it is **not** _"identical to"_! That is, we actually use reusable messages under-the-hood, but this detail is irrelevant in this context.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Rewrote Messages (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy merged PR #2591:
URL: https://github.com/apache/logging-log4j2/pull/2591


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Rewrote Messages (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #2591:
URL: https://github.com/apache/logging-log4j2/pull/2591#issuecomment-2128793585

   [As agreed with @grobmeier](https://the-asf.slack.com/archives/D02TQ7SQ9CY/p1716534032649039), merging this to wrap up the work on API docs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Rewrote Messages (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #2591:
URL: https://github.com/apache/logging-log4j2/pull/2591#discussion_r1611235544


##########
src/site/antora/modules/ROOT/pages/manual/messages.adoc:
##########
@@ -16,311 +16,361 @@
 ////
 = Messages
 
-Although Log4j 2 provides Logger methods that accept Strings and
-Objects, all of these are ultimately captured in Message objects that
-are then associated with the log event. Applications are free to
-construct Messages of their own and pass them to the Logger. Although it
-may seem more expensive than passing the message format and parameters
-directly to the event, testing has shown that with modern JVMs the cost
-of creating and destroying events is minor, especially when complex
-tasks are encapsulated in the Message instead of the application. In
-addition, when using the methods that accept Strings and parameters, the
-underlying Message object will only be created if any configured global
-filters or the Logger's log level allow the message to be processed.
-
-Consider an application that has a Map object containing \{"Name" =
-"John Doe", "Address" = "123 Main St.", "Phone" = "(999) 555-1212"} and
-a User object that has a getId method that returns "jdoe". The developer
-would like to add an informational message that returns "User John Doe
-has logged in using id jdoe". The way this could be accomplished is by
-doing:
-
-[source,java]
+Messages are a way to encapsulate the creation of logging statements.
+Developers can use them to make code more readable and reuseable.

Review Comment:
   Since `Message` is what make Log4j API apart from SLF4J, we should probably start with a more precise definition:
   
   Log4j encapsulates the data that makes up a logging statement twice:
   
   * The data **explicitly** provided by the developer in a logging call form a **log message**, which is fixed at compile time and the only **required** part of the logging statement; the log message is always convertible to a string;
   * A **log event** contains a lot of other information, like a level, timestamp, exception, location, context data, which are either provided by the developer or inferred by the logging system.
   
   So basically a developer decides the format of log messages, while the system administrator decides the format of log events.
   
   Maybe we could start with an example of formatted log event and explain the different parts using callouts. JSON seems ideal for this, since each component of a log event can be written on a separate line.
   
   I can make a proposal in a separate PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org