java - Log4j seems not to work in Spring Boot -
I add one of my existing spring
and Maven
Attempted project, and I think there is no matter how I configure, logging is going out of my control.
I tried entering log4j.properties
to src / main / java
and src / main / resources
(actually I'm not sure where to give it)
But when I use Log4j
to log in, the log is displayed only in the console,
log4j.rootlogger = DEBUG, A1 log4j.appender.a1 = org .apache.log4j FileAppender log4j.appender.A1.encoding = utf-8 log4j.appender.a1.file = e: \ programming log \ 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 whether I'm missing something or overrides spring
some settings, because I Maven
and
PS: Before adding the dependence of pom
.xml before log4j
, though I Org.apache.log4j.Logger
This way my application.java looks like this:
@configuration enabled Enable AutoConfiguration @ComponentScan ({"Hello", "Wodinow.weixin .jaskey "}) Public category applications WebMvcConfigurerAdapter {public static V oID main (string [] args) {ApplicationContext ctx = SpringApplication.run (application.class, args); System.out.println ("Check the beans provided by Spring Boot:"); String [] beanNames = ctx.getBeanDefinitionNames (); Arrays.sort (beanNames); For (string beamname: alias) {System.out.println (beanName); } LogUtil.info ("App Boots!"); // This line is not shown here in the file @Bean Public Command Service Command Service () {CommandService.getInstance return}; }}
UPDATE
By default, if you select 'Starter POM Log-in will be used for logging
(to :)
then you either add lockback logback.xml
Log4j logs (When you need more help in getting involved in Lib, please post your palm. Xml)
I use lockback (and Slough 4J)
(< ... \ java
) log4j.properties
. (In your question you have file log4j.propertie
) web.xml
web.xml :
& lt; Context-absolute & gt; & Lt; Ultimate Name & gt; Log4jConfigLocation & lt; / Lastname & gt; & Lt; Ultimate Price & gt; /WEB-INF/classes/log4j.properties< / Super-valued & gt; & Lt; / Reference param & gt; & Lt; Listener & gt; & Lt; Audience category & gt; Org.springframework.web.util.Log4jConfigListener & lt; / Listener Category & gt; & Lt; / Listener & gt;
(see @)
Comments
Post a Comment