2016-12-05 41 views
0

我最近搬到了Spring Boot,並且使用了log4j2和Sl4j,它們工作得很好。在我使用Feign,hystrix和Spring雲庫進行了很多更改之後,在某些時候,log4j日誌記錄被破壞了。我的第一個嘗試是刪除我添加的那些花哨的春季雲庫,但不幸的是,這並沒有解決問題。我在部署和初始化日誌上下文時看到一些奇怪的東西。以下是我的蹤跡。Log4j2與Slf4以及Spring Boot初始化良好,但不記錄其他任何東西

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([email protected]392b), 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 [email protected]7... 
    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 [email protected]7 OK 
    2016-12-05 15:10:35,019 main TRACE Reregistering MBeans after reconfigure. Selector=or[email protected]15761df8 
    2016-12-05 15:10:35,020 main TRACE Reregistering context (1/1): '5b2133b1' [email protected] 
    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 ([email protected]) 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, [email protected]] started OK. 
    2016-12-05 15:10:35,991 main DEBUG Using configurationFactory or[email protected]35047d03 

我很好奇註銷mBeans。因爲我的Appenders未註冊。在這下面也是沒有意義的!

TRACE Stopping  [email protected]7... 
    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 

我排除不必要的日誌記錄相關的庫從像共享記錄,07月到SLF4J,log4j的環比和SLF4J的logback東西我的類路徑中。

我有以下的罐子在我的類路徑

  1. JCL-過SLF4J:1.7.21
  2. JBoss的日誌記錄:3.3.0.Final
  3. 的log4j的API:2.6.2
  4. log4j的核心:2.6.2
  5. 的log4j-SLF4J-IMPL:2.6.2
  6. 的log4j的Web 2.4
  7. 彈簧引導起動LOG4 J2:1.4.1.RELEASE
  8. 彈簧引導啓動日誌記錄:1.4.1.RELEASE

我看到下面是我在我的-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" 
} 

燦有人請幫助我這裏發生了什麼?我也看到INFO登錄到我的控制檯。但appender似乎並沒有工作。

回答

0

-D選項我使用的是-Dlog4j.ConfigurationFile。其中一個罐子與彈簧啓動配置發生衝突。使用spring啓動的-Dlogging.config選項解決了這個問題。

相關問題