Please initialize the log4j system properly. While running web service

后端 未结 7 970
半阙折子戏
半阙折子戏 2020-12-04 17:05

Maybe it looks silly to ask this but I am confused. I referred to Configuring Log4j property but it doesn\'t seem to help.

I have written a simple web service HelloW

7条回答
  •  生来不讨喜
    2020-12-04 17:14

    You can configure log4j.properties like above answers, or use org.apache.log4j.BasicConfigurator

    public class FooImpl implements Foo {
    
        private static final Logger LOGGER = Logger.getLogger(FooBar.class);
    
        public Object createObject() {
            BasicConfigurator.configure();
            LOGGER.info("something");
            return new Object();
        }
    }
    

    So under the table, configure do:

      configure() {
        Logger root = Logger.getRootLogger();
        root.addAppender(new ConsoleAppender(
               new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
      }
    

提交回复
热议问题