I am needing to log some xml data (which is currently a JDOM Document), and I am trying to output it to a standard Java log. However, this will only produce logs with the < and > ends of the tags re-encoded as <? ?>
etc.
Although this can be parsed for the right information, it makes the log file effectively unreadable. Can anyone help with a better solution for this? I have read through a number of posts on this, but no-one seems to have come up with an answer - however, if I've missed the answer, please direct me to the right post!
Current Code: a simplified case to demonstrate what isn't working, removing the transferring of the document to XML (which can be done successfully using XMLOutputter().outputString(document)
).
try {
Logger logger = Logger.getLogger("companyname");
FileHandler fh = new FileHandler("log.log");
fh.setEncoding("UTF-8");
logger.addHandler(fh);
logger.setLevel(Level.ALL);
String message = "<tag>Some Text</tag>";
Logger.getLogger("companyname").log(Level.CONFIG, message);
}
catch (IOException e) {
e.printStackTrace();
}