Java : Log4j overwite the file path on runtime
Hi, After my previous posts concerning Java: Log4j Concepts and Explanations and Java: Log4j in practice, I would expose a solution to overwrite the file path on runtime. Libraries needed : commons-lang3-3.1.jar, commons-logging-1.1.1.jar and log4j-1.2.15.jar. MainApp.java Config.properties BUSINESS_LOG_FILE=D\:\\...\\... \\data\\results\\InjectorBusiness.log TECHNICAL_LOG_FILE=D\:\\...\\...\\data\\results\\InjectorTechnical.log LogUtil.java log4jInjector.properties log4j.rootCategory=ALL,CONSOLE,TECHNICALLOGFILE log4j.logger.com.ho.log4j.test2.LogUtil=INFO,BUSINESSLOGFILE #------------------- CONSOLE -------------------------- log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern= %m%n log4j.appender.CONSOLE.Threshold=INFO #------------------- FILE -------------------------- log4j.appender.TECHNICALLOGFILE=org.apache.log4j.RollingFileAppender log4j.appender.TECHNICALLOGFILE.File=injectortech.log log4j.appender.TECHNICALLOGFILE.MaxFileSize=30MB log4j.appender.TECHNICALLOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.TECHNICALLOGFILE.layout.ConversionPattern=%d{ABSOLUTE} %5p %c - %m%n log4j.appender.TECHNICALLOGFILE.Threshold=ALL #------------------- BUSINESSLOGFILE -------------------------- log4j.appender.BUSINESSLOGFILE=org.apache.log4j.DailyRollingFileAppender #log4j.appender.BUSINESSLOGFILE.File=${catalina.base}/logs/Injector.log log4j.appender.BUSINESSLOGFILE.File=injector.log log4j.appender.BUSINESSLOGFILE.DatePattern='.'yyy-MM-dd-HH log4j.appender.BUSINESSLOGFILE.MaxFileSize=30MB log4j.appender.BUSINESSLOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.BUSINESSLOGFILE.Threshold=ALL log4j.appender.BUSINESSLOGFILE.Append=true log4j.appender.BUSINESSLOGFILE.layout.ConversionPattern=%-d{MMM dd HH:mm:ss} %-5p %c %M %m%n Execute the MainApp class with the following program ...more»