I'm trying to avoid the possibility of log forging in our java based webservice application that uses log4j. Since we do not use any html based log viewer, we do not need to encode HTML contents in the log messages. I just want to avoid new line characters. So if there are any \n or \r in the log message, print them as spaces instead of actually doing a new line.
I prefer not to use any extra jars. For example, using ESAPI requires all the classes to be changed from Logger.getLogger(ClassName1.class);
to ESAPI.getLogger(ClassName1.class)
, and whereever you print logs needs to be changed from logger.info("message")
to logger.info(Logger.EVENT_SUCCESS, "message")
which we do NOT want to do for all the existing codebase. Also using the ESAPI adds extra content to each log entries which is unnecessary.
Is there any log4j configurations to make it replace \n or \r into spaces for all the things it logs? If not, is there any simple wrappers on top of log4j that does this functionality?