Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a uniform Log4j 1.x message factory #767

Merged
merged 1 commit into from Mar 4, 2022

Conversation

ppkarwasz
Copy link
Contributor

@ppkarwasz ppkarwasz commented Feb 21, 2022

This PR provides a factory method that decides the type of message based on the runtime type of the logged object (cf. LOG4J2-3080).

Before the implementations of maybeLog and forcedLog created different types of messages.

((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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

* @param map a generic map
* @return a {@link StringMap}
*/
public static SortedArrayStringMap fromGenericMap(final Map<?, ?> map) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This PR provides a factory method 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)).

These are applied to both `maybeLog` and `forceLog`.
@ppkarwasz ppkarwasz changed the title [LOG4J2-3410] Fix ClassCastException when key is not a string Provide a uniform Log4j 1.x message factory Feb 21, 2022
Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ppkarwasz ppkarwasz merged commit b03d760 into apache:release-2.x Mar 4, 2022
@ppkarwasz ppkarwasz deleted the log4j1-message-factory branch March 4, 2022 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants