1

I'm working on a spring boot/maven project that I created with SpringIntializr. If I add all the necessary dependencies to my pom, and if I add my log4j2.xml to MyApp/src/main/resources, and if after a build I see my log4j2.xml file in MyApp/target/classes, does that mean that the log4j config has been successfully added to the classpath?

I asked a more comprehensive question here, but thought this issue might merit a standalone question

badperson
  • 1,554
  • 3
  • 19
  • 41
  • When you run the app, IDE prints the command line which includes the classpath. If you see this directory in the command line classpath, then it's there. – CrazyCoder Dec 06 '21 at 21:57

1 Answers1

0

Basically yes, what gets to the classes, later on, gets handled by the spring-boot maven plugin and should be available in the artifact that you build. At this point it doesn't really matter whether it was originally in the src/main/resources folder or not.

Having said that, log4j2 is not used by spring boot by default (it uses logback), so you should set it up For such a setup see this example

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • that has the same problem...I get the log output in the main spring log, but the file defined in the log4j2.xml file is not created – badperson Dec 06 '21 at 22:54
  • Check the resulting artifact (jar). Does it have lo4j2.xml packed inside? Does it have a log4j2 starter does it have other starters of logging in the BOOT-INF/lib folder? – Mark Bramnik Dec 06 '21 at 22:58