I'm migrating a large application from Log4j1 to Log4j2 following the Migration Guide (Option 2 by Apache). The project is a large and modularized and I don't have the knowledge on how every module works. When reading the Migration Guide (Option 2 by Apache) it was said, that I have to change a couple package names, change Logger into LogManager, use another way to set the Levels and change how String concatenation works. But nowhere it was mentioned that a whole bunch of modules won't work anymore because they contain classes that extend Layout or PatternLayout. I don't want to delete the classes and I don't want to change it's implementation with the help of the properties file. I'm quite positive that the functionality can't be reproduced with the help of the properties file. So what is the equivalent of Layout and PatternLayout in Log4j2? Here is a small example of a class that extends from Layout:
public class MXMLLayout extends Layout {
@Override
public String format(LoggingEvent event) {
MXMLHelper helper = new MXMLHelper();
String message = (String) event.getMessage();
String[] secondLevel = {};
String attributes = "";
String attrNumber = "";
boolean flagProcessInst = false;
boolean flagAudit = false;
boolean flagProcess = false;
int in = -1;
String[] firstLevel = null;
if (message.contains(MXMLCommandCenter.AUDIT_TRAIL_SEP) && (!message
.contains(MXMLCommandCenter.PROCESS_INST_SEP)
|| !message.contains(MXMLCommandCenter.PROCESS_SEP))) {
firstLevel = message.split(MXMLCommandCenter.AUDIT_TRAIL_SEP);
flagAudit = true;
} else if (message.contains(MXMLCommandCenter.PROCESS_INST_SEP)
&& (!message.contains(MXMLCommandCenter.AUDIT_TRAIL_SEP)
|| !message.contains(
MXMLCommandCenter.PROCESS_SEP))) {
firstLevel = message.split(MXMLCommandCenter.PROCESS_INST_SEP);
flagProcessInst = true;
} else if (message.contains(MXMLCommandCenter.PROCESS_SEP) && (!message
.contains(MXMLCommandCenter.AUDIT_TRAIL_SEP)
|| !message.contains(
MXMLCommandCenter.PROCESS_INST_SEP))) {
firstLevel = message.split(MXMLCommandCenter.PROCESS_SEP);
flagProcess = true;
} else {
firstLevel = new String[0];
}
// [ ... ]
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(MXMLCommandCenter.FILE));
} catch (Exception e) {
JFrame frame = new JFrame();
JOptionPane.showMessageDialog(frame,
"The MXML log file has been deleted.",
"MXMLPlugin Error", JOptionPane.ERROR_MESSAGE);
frame.dispose();
MXMLCommandCenter.lockEnvironment();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException exc) {
exc.printStackTrace();
}
}
// [ ... ]
}
I have several large complex classes that make use of the Layout/PatternLayout. Do I have to analyze them all and seek for alternative implementations because I wanted to upgrade the logging framework?