I tried adding Spring and Maven to one of my existing projects, and I found that no matter how I set up, logging seems to be out of my control.
I tried putting log4j.properties in src/main/java and src/main/resources (actually I'm not sure where to put it).
But when I use Log4j for registration, the log is displayed only in the console, although I configure it to a file.
My log4j.properties looks like this:
log4j.rootLogger=DEBUG, A1 log4j.appender.A1=org.apache.log4j.FileAppender log4j.appender.A1.encoding=utf-8 log4j.appender.A1.File=E:\Programminglog\debug.log log4j.appender.A1.Threshold = DEBUG log4j.appender.A1.Append=true log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
I'm not sure if I will miss something or Spring is overriding some settings, as I am new to Maven and Spring .
PS: before adding the Log4j dependencies to the pom .xml compilation errors, although I use org.apache.log4j.Logger
This is what my application.java application looks like:
@Configuration @EnableAutoConfiguration @ComponentScan({"hello","wodinow.weixin.jaskey"}) public class Application extends WebMvcConfigurerAdapter { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); System.out.println("Let inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } LogUtil.info("Application Boots!");

source share