Spring boot 带有Slf4和Spring Boot的Log4j2初始化良好,但don';我不记录其他的事情

Spring boot 带有Slf4和Spring Boot的Log4j2初始化良好,但don';我不记录其他的事情,spring-boot,slf4j,log4j2,Spring Boot,Slf4j,Log4j2,我最近搬到了Spring Boot,使用的是log4j2和Sl4j,它们工作得非常好。在我使用Feign、hystrix和Spring云库做了很多更改之后,log4j日志记录在某个时候被破坏了。我的第一次尝试是删除我添加的那些奇特的spring云库,但不幸的是,这并没有解决这个问题。在部署和初始化日志上下文的过程中,我看到了一些奇怪的东西。下面是我的踪迹 Initializing configuration XmlConfiguration[location=/com/config/my-

我最近搬到了Spring Boot,使用的是log4j2和Sl4j,它们工作得非常好。在我使用Feign、hystrix和Spring云库做了很多更改之后,log4j日志记录在某个时候被破坏了。我的第一次尝试是删除我添加的那些奇特的spring云库,但不幸的是,这并没有解决这个问题。在部署和初始化日志上下文的过程中,我看到了一些奇怪的东西。下面是我的踪迹

   Initializing configuration XmlConfiguration[location=/com/config/my-service/log4j2.xml]
   2016-12-05 15:10:33,748 main DEBUG Installed script engines
   2016-12-05 15:10:34,403 main DEBUG Oracle Nashorn Version: 1.8.0_25, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
   2016-12-05 15:10:34,404 main DEBUG PluginManager 'Core' found 101 plugins
   2016-12-05 15:10:34,404 main DEBUG PluginManager 'Level' found 0 plugins
   2016-12-05 15:10:34,413 main DEBUG Starting 1 Log4j2Scheduled threads
   2016-12-05 15:10:34,418 main DEBUG Building Plugin[name=property, class=org.apache.logging.log4j.core.config.Property].
   2016-12-05 15:10:34,456 main TRACE TypeConverterRegistry initializing.
   2016-12-05 15:10:34,457 main DEBUG PluginManager 'TypeConverter' found 23 plugins
   2016-12-05 15:10:34,472 main DEBUG createProperty(name="log-path", value="/com/logs")
   2016-12-05 15:10:34,473 main DEBUG Building Plugin[name=property, class=org.apache.logging.log4j.core.config.Property].
   2016-12-05 15:10:34,474 main DEBUG createProperty(name="module", value="my-service")
   2016-12-05 15:10:34,474 main DEBUG Building Plugin[name=properties, class=org.apache.logging.log4j.core.config.PropertiesPlugin].
   2016-12-05 15:10:34,483 main DEBUG configureSubstitutor(={log-path=/com/logs, module=my-service}, Configuration(SERVICE))
   2016-12-05 15:10:34,484 main DEBUG PluginManager 'Lookup' found 14 plugins
   2016-12-05 15:10:34,486 main DEBUG Building Plugin[name=layout, class=com.mycompany.logging.jsonlayout.log4j2.MycompanyJsonLayout].
   2016-12-05 15:10:34,487 main DEBUG createLayout(pretty="true", layoutVersion="2", showOrigin="false")
   2016-12-05 15:10:34,894 main DEBUG Building Plugin[name=SizeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy].
   2016-12-05 15:10:34,897 main DEBUG createPolicy(size="100 MB")
   2016-12-05 15:10:34,899 main DEBUG Building Plugin[name=Policies, class=org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy].
   2016-12-05 15:10:34,900 main DEBUG createPolicy(={SizeBasedTriggeringPolicy(size=104857600)})
   2016-12-05 15:10:34,900 main DEBUG Building Plugin[name=DefaultRolloverStrategy, class=org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy].
   2016-12-05 15:10:34,902 main DEBUG createStrategy(max="1", min="null", fileIndex="null", compressionLevel="null", ={}, stopCustomActionsOnError="true", Configuration(SERVICE))
   2016-12-05 15:10:34,904 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.RollingFileAppender].
   2016-12-05 15:10:34,908 main DEBUG createAppender(fileName="/com/logs/my-service.json", filePattern="/com/logsmy-service.json.%i.gz", append="null", name="comjson", bufferedIO="null", bufferSize="null", immediateFlush="null", Policies(CompositeTriggeringPolicy(policies=[SizeBasedTriggeringPolicy(size=104857600)])), DefaultRolloverStrategy(DefaultRolloverStrategy(min=1, max=1)), MycompanyJsonLayout(com.mycompany.logging.jsonlayout.log4j2.MycompanyJsonLayout@41ee392b), Filter=null, ignoreExceptions="null", advertise="null", advertiseURI="null", Configuration(SERVICE))
   2016-12-05 15:10:34,914 main DEBUG Starting RollingFileManager /com/logs/my-service.json
   2016-12-05 15:10:34,914 main DEBUG PluginManager 'FileConverter' found 2 plugins
   2016-12-05 15:10:34,915 main DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
   2016-12-05 15:10:34,916 main DEBUG createAppenders(={comjson})
   2016-12-05 15:10:34,917 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
   2016-12-05 15:10:34,918 main DEBUG createAppenderRef(ref="comjson", level="null", Filter=null)
   2016-12-05 15:10:34,918 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
   2016-12-05 15:10:34,927 main DEBUG createLogger(additivity="false", level="DEBUG", name="com.mycompany.ecommerce", includeLocation="null", ={comjson}, ={}, Configuration(SERVICE), Filter=null)
   2016-12-05 15:10:34,931 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
   2016-12-05 15:10:34,933 main DEBUG createLogger(additivity="true", level="DEBUG", name="com.mycompany.service.interceptor", includeLocation="null", ={}, ={}, Configuration(SERVICE), Filter=null)
   2016-12-05 15:10:34,933 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
   2016-12-05 15:10:34,935 main DEBUG createLogger(additivity="true", level="DEBUG", name="com.com", includeLocation="null", ={}, ={}, Configuration(SERVICE), Filter=null)
   2016-12-05 15:10:34,936 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
   2016-12-05 15:10:34,937 main DEBUG createLogger(additivity="true", level="INFO", name="performance", includeLocation="null", ={}, ={}, Configuration(SERVICE), Filter=null)
   2016-12-05 15:10:34,938 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
   2016-12-05 15:10:34,939 main DEBUG createLogger(additivity="true", level="INFO", name="com.mycompany.ecommerce.health", includeLocation="null", ={}, ={}, Configuration(SERVICE), Filter=null)
   2016-12-05 15:10:34,939 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
   2016-12-05 15:10:34,940 main DEBUG createAppenderRef(ref="comjson", level="null", Filter=null)
   2016-12-05 15:10:34,941 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
   2016-12-05 15:10:34,942 main DEBUG createLogger(additivity="null", level="INFO", includeLocation="null", ={comjson}, ={}, Configuration(SERVICE), Filter=null)
   2016-12-05 15:10:34,942 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
   2016-12-05 15:10:34,944 main DEBUG createLoggers(={com.mycompany.ecommerce, com.mycompany.service.interceptor, com.com, performance, com.mycompany.ecommerce.health, root})
   2016-12-05 15:10:34,946 main DEBUG Configuration XmlConfiguration[location=/com/config/my-service/log4j2.xml] initialized
   2016-12-05 15:10:34,946 main DEBUG Starting configuration XmlConfiguration[location=/com/config/my-service/log4j2.xml]
   2016-12-05 15:10:34,948 main DEBUG Started configuration XmlConfiguration[location=/com/config/my-service/log4j2.xml] OK.
   2016-12-05 15:10:34,957 main TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@87aac27...
   2016-12-05 15:10:34,957 main TRACE DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
   2016-12-05 15:10:34,958 main TRACE DefaultConfiguration stopping root LoggerConfig.
   2016-12-05 15:10:34,958 main TRACE DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
   2016-12-05 15:10:34,958 main TRACE DefaultConfiguration stopping remaining Appenders.
   2016-12-05 15:10:34,959 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
   2016-12-05 15:10:34,959 main TRACE DefaultConfiguration stopped 1 remaining Appenders.
   2016-12-05 15:10:34,960 main TRACE DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
   2016-12-05 15:10:34,960 main DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@87aac27 OK
   2016-12-05 15:10:35,019 main TRACE Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector@15761df8
   2016-12-05 15:10:35,020 main TRACE Reregistering context (1/1): '5b2133b1' org.apache.logging.log4j.core.LoggerContext@6ab7a896
   2016-12-05 15:10:35,023 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1'
   2016-12-05 15:10:35,023 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=StatusLogger'
   2016-12-05 15:10:35,024 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=ContextSelector'
   2016-12-05 15:10:35,024 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=*'
   2016-12-05 15:10:35,025 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=Appenders,name=*'
   2016-12-05 15:10:35,025 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=AsyncAppenders,name=*'
   2016-12-05 15:10:35,026 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=AsyncLoggerRingBuffer'
   2016-12-05 15:10:35,026 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=*,subtype=RingBuffer'
   2016-12-05 15:10:35,029 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1
   2016-12-05 15:10:35,038 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=StatusLogger
   2016-12-05 15:10:35,040 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=ContextSelector
   2016-12-05 15:10:35,043 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=
   2016-12-05 15:10:35,044 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=performance
   2016-12-05 15:10:35,044 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=com.com
   2016-12-05 15:10:35,044 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=com.mycompany.ecommerce
   2016-12-05 15:10:35,045 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=com.mycompany.service.interceptor
   2016-12-05 15:10:35,045 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Loggers,name=com.mycompany.ecommerce.health
   2016-12-05 15:10:35,047 main DEBUG Registering MBean org.apache.logging.log4j2:type=5b2133b1,component=Appenders,name=comjson
   2016-12-05 15:10:35,052 main TRACE Using default SystemClock for timestamps.
   2016-12-05 15:10:35,052 main TRACE Using DummyNanoClock for nanosecond timestamps.
   2016-12-05 15:10:35,053 main DEBUG Reconfiguration complete for context[name=5b2133b1] at URI /com/config/my-service/log4j2.xml (org.apache.logging.log4j.core.LoggerContext@6ab7a896) with optional ClassLoader: null
   2016-12-05 15:10:35,053 main DEBUG Shutdown hook enabled. Registering a new one.
   2016-12-05 15:10:35,054 main DEBUG LoggerContext[name=5b2133b1, org.apache.logging.log4j.core.LoggerContext@6ab7a896] started OK.
   2016-12-05 15:10:35,991 main DEBUG Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@35047d03
我对未注册的MBean非常好奇。因为我的appender没有注册。下面这个对我来说也没有意义

    TRACE Stopping       org.apache.logging.log4j.core.config.DefaultConfiguration@87aac27...
  2016-12-05 15:10:34,957 main TRACE DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
  2016-12-05 15:10:34,958 main TRACE DefaultConfiguration stopping root LoggerConfig.
  2016-12-05 15:10:34,958 main TRACE DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
  2016-12-05 15:10:34,958 main TRACE DefaultConfiguration stopping remaining Appenders.
  2016-12-05 15:10:34,959 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
  2016-12-05 15:10:34,959 main TRACE DefaultConfiguration stopped 1 remaining Appenders.
  2016-12-05 15:10:34,960 main TRACE DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
  2016-12-05 15:10:34,960 main DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration
我从我的类路径中排除了不必要的日志相关库,比如commons日志、jul-to-slf4j、log4j-over-slf4j和logback之类的东西

我的类路径中确实有以下jar

  • jcl-over-slf4j:1.7.21
  • jboss日志:3.3.0.Final
  • log4j api:2.6.2
  • log4j核心:2.6.2
  • log4j-slf4j-impl:2.6.2
  • log4jweb:2.4
  • spring-boot-starter-log4j2:1.4.1.1释放
  • spring启动程序日志记录:1.4.1.1版本
  • 我看到的都是我的my-service.json文件

    {
     "time" : "2016-12-05T21:22:08.742Z",
     "service" : { },
     "message" : {
       "category" : "org.eclipse.jetty.util.log",
       "severity" : "INFO",
       "text" : "Logging initialized @2227ms"
     },
     "v" : "2"
    }
    

    有人能帮我做点什么吗?我也在我的控制台中看到信息日志。但appenders似乎不起作用。

    -D我使用的选项是-Dlog4j.ConfigurationFile。其中一个拉入的罐子与弹簧靴配置冲突。使用spring boot的-dloging.config选项解决了该问题

    -D我使用的选项是-Dlog4j.ConfigurationFile。其中一个拉入的罐子与弹簧靴配置冲突。使用spring boot的-dloging.config选项解决了该问题