Saturday, February 22, 2014

log4j.properties

Things to remember :-):

  • The  log4j.properties  is searched in the class path.
  • The rootLogger properties are inherited by all loggers in terms of appenders (if for instance it has a console appender all other defined loggers will have also this appender even if not specifically configured)
In order to configure your specific logger(s):
  • add the desired appender(s) (like below):
    • log4j.appender.myLog=org.apache.log4j.FileAppender
    • log4j.appender.myLog.File=logs/myLog.txt
    • log4j.appender.myLog.layout=org.apache.log4j.PatternLayout
    • log4j.appender.myLog.layout.conversionPattern=%-5p %d [%t] %c: %m%n
  • add the logger by specifying logging level and appender(s):
    • log4j.logger.myLog=DEBUG, myLog

The actual place where the logs will be generated depend on the implicit/explicit setting for the working directory of your application;  to have a more specific control over this behaviour you can use environment variables expansion like:

  • log4j.appender.file.File=${mule.home}/logs/mule-logging-example.log

No comments :

Post a Comment