String resource = "/log4j.properties"; // / is necessary URL configFileResource = Log4JTest.class.getResource(resource); PropertyConfigurator.configure(configFileResource); log4j.properties #default one log4j.rootLogger=DEBUG, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%p [%t] %c{2} (%M:%L) - %m%n #under package example log4j.logger.example=INFO, A2 log4j.appender.A2=org.apache.log4j.FileAppender log4j.appender.A2.File=${user.home}/test.txt log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n