You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/02/21 15:20:31 UTC

[GitHub] [logging-log4j2] ppkarwasz opened a new pull request #767: [LOG4J2-3410] Fix ClassCastException when key is not a string

ppkarwasz opened a new pull request #767:
URL: https://github.com/apache/logging-log4j2/pull/767


   This PR provides a `MessageFactory` that decides the type of message based on the runtime type of the logged object (cf. [LOG4J2-3080](https://issues.apache.org/jira/browse/LOG4J2-3080)).
   
   If the logged object is a map, it is converted into a `StringMap` in a typesafe way.


-- 
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: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767: Provide a uniform Log4j 1.x message factory

Posted by Gary Gregory <ga...@gmail.com>.
That's up to you ;-)

Gary

On Fri, Mar 4, 2022, 17:20 Piotr P. Karwasz <pi...@gmail.com> wrote:

> Thanks Gary,
>
> I updated the change list, although I am still not sure which changes
> should be there and which are irrelevant for the users.
>
> Piotr
>
>
> On Fri, Mar 4, 2022 at 9:10 PM Gary Gregory <ga...@gmail.com>
> wrote:
> >
> > Hi Piotr and welcome aboard.
> >
> > I usually update changes.xml but not in a PR, we generate the release
> notes
> > from changes.xml.
> >
> > Gary
> >
> > ---------- Forwarded message ---------
> > From: GitBox <gi...@apache.org>
> > Date: Fri, Mar 4, 2022 at 2:57 PM
> > Subject: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767:
> > Provide a uniform Log4j 1.x message factory
> > To: <no...@logging.apache.org>
> >
> >
> >
> > ppkarwasz merged pull request #767:
> > URL: https://github.com/apache/logging-log4j2/pull/767
> >
> >
> >
> >
> >
> > --
> > 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: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767: Provide a uniform Log4j 1.x message factory

Posted by Ralph Goers <ra...@dslextreme.com>.
In general, if it requires a Jira issue then it should require a changes.xml entry. 

Usually, PRs require Jira issues. However, simple doc updates and dependency 
updates don’t necessarily require Jira issues although I would prefer to see it 
handled differently. But since Gary is the one who seems to spend the most time 
updating dependencies he tends to do it in whatever way works for him. Personally, 
I would prefer a single Jira issue for each release and have all the dependency 
updates be tracked in that.

Ralph

> On Mar 4, 2022, at 3:19 PM, Piotr P. Karwasz <pi...@gmail.com> wrote:
> 
> Thanks Gary,
> 
> I updated the change list, although I am still not sure which changes
> should be there and which are irrelevant for the users.
> 
> Piotr
> 
> 
> On Fri, Mar 4, 2022 at 9:10 PM Gary Gregory <ga...@gmail.com> wrote:
>> 
>> Hi Piotr and welcome aboard.
>> 
>> I usually update changes.xml but not in a PR, we generate the release notes
>> from changes.xml.
>> 
>> Gary
>> 
>> ---------- Forwarded message ---------
>> From: GitBox <gi...@apache.org>
>> Date: Fri, Mar 4, 2022 at 2:57 PM
>> Subject: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767:
>> Provide a uniform Log4j 1.x message factory
>> To: <no...@logging.apache.org>
>> 
>> 
>> 
>> ppkarwasz merged pull request #767:
>> URL: https://github.com/apache/logging-log4j2/pull/767
>> 
>> 
>> 
>> 
>> 
>> --
>> 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: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767: Provide a uniform Log4j 1.x message factory

Posted by "Piotr P. Karwasz" <pi...@gmail.com>.
Thanks Gary,

I updated the change list, although I am still not sure which changes
should be there and which are irrelevant for the users.

Piotr


On Fri, Mar 4, 2022 at 9:10 PM Gary Gregory <ga...@gmail.com> wrote:
>
> Hi Piotr and welcome aboard.
>
> I usually update changes.xml but not in a PR, we generate the release notes
> from changes.xml.
>
> Gary
>
> ---------- Forwarded message ---------
> From: GitBox <gi...@apache.org>
> Date: Fri, Mar 4, 2022 at 2:57 PM
> Subject: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767:
> Provide a uniform Log4j 1.x message factory
> To: <no...@logging.apache.org>
>
>
>
> ppkarwasz merged pull request #767:
> URL: https://github.com/apache/logging-log4j2/pull/767
>
>
>
>
>
> --
> 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

Fwd: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767: Provide a uniform Log4j 1.x message factory

Posted by Gary Gregory <ga...@gmail.com>.
Hi Piotr and welcome aboard.

I usually update changes.xml but not in a PR, we generate the release notes
from changes.xml.

Gary

---------- Forwarded message ---------
From: GitBox <gi...@apache.org>
Date: Fri, Mar 4, 2022 at 2:57 PM
Subject: [GitHub] [logging-log4j2] ppkarwasz merged pull request #767:
Provide a uniform Log4j 1.x message factory
To: <no...@logging.apache.org>



ppkarwasz merged pull request #767:
URL: https://github.com/apache/logging-log4j2/pull/767





-- 
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

[GitHub] [logging-log4j2] ppkarwasz merged pull request #767: Provide a uniform Log4j 1.x message factory

Posted by GitBox <gi...@apache.org>.
ppkarwasz merged pull request #767:
URL: https://github.com/apache/logging-log4j2/pull/767


   


-- 
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



[GitHub] [logging-log4j2] garydgregory commented on a change in pull request #767: [LOG4J2-3410] Fix ClassCastException when key is not a string

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in pull request #767:
URL: https://github.com/apache/logging-log4j2/pull/767#discussion_r811358091



##########
File path: log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java
##########
@@ -128,6 +128,21 @@
     private boolean immutable;
     private transient boolean iterating;
 
+    /**
+     * Transforms a generic map to a {@link StringMap} by mapping the keys to
+     * {@link String}.
+     * 
+     * @param map a generic map
+     * @return a {@link StringMap}
+     */
+    public static SortedArrayStringMap fromGenericMap(final Map<?, ?> map) {

Review comment:
       I don't think this is needed, would you check your tests against HEAD, without any main changes?




-- 
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



[GitHub] [logging-log4j2] ppkarwasz commented on a change in pull request #767: [LOG4J2-3410] Fix ClassCastException when key is not a string

Posted by GitBox <gi...@apache.org>.
ppkarwasz commented on a change in pull request #767:
URL: https://github.com/apache/logging-log4j2/pull/767#discussion_r811231397



##########
File path: log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
##########
@@ -309,15 +309,10 @@ private void fireRemoveAppenderEvent(final Appender appender) {
 
     public void forcedLog(final String fqcn, final Priority level, final Object message, final Throwable t) {
         final org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
+        final Message msg = LegacyMessageFactory.INSTANCE.newMessage(message);
         if (logger instanceof ExtendedLogger) {
-            @SuppressWarnings("unchecked")
-            final Message msg = message instanceof Message ? (Message) message
-                : message instanceof Map ? new MapMessage((Map) message) : new ObjectMessage(message);
             ((ExtendedLogger) logger).logMessage(fqcn, lvl, null, msg, t);
         } else {
-            final ObjectRenderer renderer = get(message.getClass());
-            final Message msg = message instanceof Message ? (Message) message
-                : renderer != null ? new RenderedMessage(renderer, message) : new ObjectMessage(message);

Review comment:
       The `RenderedMessage` case is omitted, since this would require a stateful `MessageFactory` (per category).
   
   Anyway there is currently no way to add elements to the `RendererMap`.




-- 
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



[GitHub] [logging-log4j2] ppkarwasz commented on a change in pull request #767: Provide a uniform Log4j 1.x message factory

Posted by GitBox <gi...@apache.org>.
ppkarwasz commented on a change in pull request #767:
URL: https://github.com/apache/logging-log4j2/pull/767#discussion_r811369316



##########
File path: log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java
##########
@@ -128,6 +128,21 @@
     private boolean immutable;
     private transient boolean iterating;
 
+    /**
+     * Transforms a generic map to a {@link StringMap} by mapping the keys to
+     * {@link String}.
+     * 
+     * @param map a generic map
+     * @return a {@link StringMap}
+     */
+    public static SortedArrayStringMap fromGenericMap(final Map<?, ?> map) {

Review comment:
       @garydgregory: after your fix it is not needed anymore.
   




-- 
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