Skip to content

Transform plugin removes throwable information #169

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

Open
YanivKunda opened this issue Feb 19, 2025 · 0 comments
Open

Transform plugin removes throwable information #169

YanivKunda opened this issue Feb 19, 2025 · 0 comments

Comments

@YanivKunda
Copy link

In a simple use case, e.g.:

        logger.error("Hello, {}!", "Problem", new Exception("Oh oh"));

Without the transform plugin, the default parameterized message formatter captures the last argument as a throwable -
if it's the last argument and the previous argument count match the placeholder count.
When processed by the ExtendedThrowablePatternConverter, it is fetched -
from LogEvent.getThrown(), which was previously populated when the LogEvent was created, from Message.getThrowable().
This provides the throwable pattern converter the information to format the throwable as a message/stacktrace.

Here is the code generated by the transform plugin:

        Logger var10000 = logger;
        Object log4j2$$p0 = new Exception("Oh oh");
        Object log4j2$$p1 = "Problem";
        Object log4j2$$p2 = "Hello, {}!";
        var10000.atError().withLocation(Cache.locations[0]).log(log4j2$$p2, log4j2$$p1, log4j2$$p0);

It create a LogBuilder, but does not use its .withThrowable(Throwable) method -
leading to a LogEvent that does not have the throwable set.

My thought is that to resolve that, the transform plugin needs - at build time - to analyze the logger call in the same way the logger does to extract the throwable arg and set it using .withThrowable(Throwable).
An alternative (might be simpler) - is to change the DefaultLogBuilder (in log4j-api), so that DefaultLogBuilder.logMessage(Message) changes from

            logger.logMessage(level, marker, fqcn, location, message, throwable);

to something like

            logger.logMessage(level, marker, fqcn, location, message, throwable != null ? throwable : message.getThrowable());
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

No branches or pull requests

1 participant