mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Backport PR #14727 to 7.17: Avoid the wrapping of LogstashMessageFactory with log4j's MessageFactory adapter #14742
Starting with Log4j2 2.6 if a subclass of MessageFactory associated with an Logger instance
is not subclass of MessageFactory2, then it's wrapped with MessageFactory2Adapter.
This trigger a log4j warn log that, when a class subclasses LogStash::Plugin for example, is noisy and report about
a Logger is not associated with the default MessagedFactory (LogstashMessageFactory) every time a subclass of Plugins is instantiated.
This commit adapt LogstashMessageFactory to implement the MessagedFactory2 instead of the older MessageFactory to avoid the wrapping with the adapter class.
(cherry picked from commit 05bfaff799
)
Co-authored-by: Andrea Selva <selva.andre@gmail.com>
This commit is contained in:
parent
3a8076b066
commit
810e005aab
1 changed files with 59 additions and 2 deletions
|
@ -21,7 +21,7 @@
|
|||
package org.logstash.log;
|
||||
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
import org.apache.logging.log4j.message.MessageFactory;
|
||||
import org.apache.logging.log4j.message.MessageFactory2;
|
||||
import org.apache.logging.log4j.message.ObjectMessage;
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.logging.log4j.message.SimpleMessage;
|
||||
|
@ -30,8 +30,10 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* Used in Log4j configuration.
|
||||
*
|
||||
* Requires Log4j 2.6 and above.
|
||||
* */
|
||||
public final class LogstashMessageFactory implements MessageFactory {
|
||||
public final class LogstashMessageFactory implements MessageFactory2 {
|
||||
|
||||
public static final LogstashMessageFactory INSTANCE = new LogstashMessageFactory();
|
||||
|
||||
|
@ -53,4 +55,59 @@ public final class LogstashMessageFactory implements MessageFactory {
|
|||
return new ParameterizedMessage(message, params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(CharSequence charSequence) {
|
||||
return new SimpleMessage(charSequence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0) {
|
||||
return newMessage(message, new Object[]{p0});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1) {
|
||||
return newMessage(message, new Object[]{p0, p1});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3, Object p4) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3, p4});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3, p4, p5});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3, p4, p5, p6});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3, p4, p5, p6, p7});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3, p4, p5, p6, p7, p8});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message newMessage(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) {
|
||||
return newMessage(message, new Object[]{p0, p1, p2, p3, p4, p5, p6, p7, p8, p9});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue