I'm using "\n" in my Strings, but instead of a linefeed in the syslog, it actually shows a "\n". Any ideas? I noticed that the exception hierarchy is separated by newlines in the syslog so there should be a way to do it. I'm using log4j 1.2.7 and JDK 1.4.1_01 on Solaris 2.7. Thanks! Console output that converts "\n" to newlines: > java -cp log4j.jar:. Log4JTest localhost local7 [DEBUG] [Log4JTest] - debug: debug logged [INFO ] [Log4JTest] - info: info logged [WARN ] [Log4JTest] - warn: warn logged [ERROR] [Log4JTest] - error: error logged [FATAL] [Log4JTest] - fatal: fatal logged [DEBUG] [Log4JTest] - Exception caught java.lang.Exception: exception: user-generated exception at Log4JTest.main(Log4JTest.java:84) [INFO ] [Log4JTest] - Exception caught java.lang.Exception: exception: user-generated exception at Log4JTest.main(Log4JTest.java:84) [WARN ] [Log4JTest] - Exception caught java.lang.Exception: exception: user-generated exception at Log4JTest.main(Log4JTest.java:84) [ERROR] [Log4JTest] - Exception caught java.lang.Exception: exception: user-generated exception at Log4JTest.main(Log4JTest.java:84) [FATAL] [Log4JTest] - Exception caught java.lang.Exception: exception: user-generated exception at Log4JTest.main(Log4JTest.java:84) Syslog file which does not: Dec 17 11:29:06 localhost [DEBUG] [Log4JTest] - debug:\ndebug logged Dec 17 11:29:06 localhost [INFO ] [Log4JTest] - info:\ninfo logged Dec 17 11:29:06 localhost [WARN ] [Log4JTest] - warn:\nwarn logged Dec 17 11:29:06 localhost [ERROR] [Log4JTest] - error:\nerror logged Dec 17 11:29:06 localhost [FATAL] [Log4JTest] - fatal:\nfatal logged Dec 17 11:29:06 localhost [DEBUG] [Log4JTest] - Exception caught Dec 17 11:29:06 localhost java.lang.Exception: exception:\nuser-generated exception Dec 17 11:29:06 localhost at Log4JTest.main(Log4JTest.java:84) Dec 17 11:29:06 localhost [INFO ] [Log4JTest] - Exception caught Dec 17 11:29:06 localhost java.lang.Exception: exception:\nuser-generated exception Dec 17 11:29:06 localhost at Log4JTest.main(Log4JTest.java:84) Dec 17 11:29:06 localhost [WARN ] [Log4JTest] - Exception caught Dec 17 11:29:06 localhost java.lang.Exception: exception:\nuser-generated exception Dec 17 11:29:06 localhost at Log4JTest.main(Log4JTest.java:84) Dec 17 11:29:06 localhost [ERROR] [Log4JTest] - Exception caught Dec 17 11:29:06 localhost java.lang.Exception: exception:\nuser-generated exception Dec 17 11:29:06 localhost at Log4JTest.main(Log4JTest.java:84) Dec 17 11:29:06 localhost [FATAL] [Log4JTest] - Exception caught Dec 17 11:29:06 localhost java.lang.Exception: exception:\nuser-generated exception Dec 17 11:29:06 localhost at Log4JTest.main(Log4JTest.java:84)
Sample code: ... PatternLayout patternLayout = new PatternLayout("[%-5p] [%c] - %m%n"); ... logger.debug("debug:\ndebug logged"); logger.info("info:\ninfo logged"); logger.warn("warn:\nwarn logged"); logger.error("error:\nerror logged"); logger.fatal("fatal:\nfatal logged"); try { throw new Exception("exception:\nuser-generated exception"); } catch(Exception e) { logger.debug("Exception caught", e); logger.info("Exception caught", e); logger.warn("Exception caught", e); logger.error("Exception caught", e); logger.fatal("Exception caught", e); } ...