日志系统的组成

出自Alibaba Webx框架手册baobao的总结,写的非常好 http://openwebx.org/

       在某些遗留系统中,有些代码直接用到了Log4j API(例如Log4j Appender)。假如,我们仍然希望SLF4J以logback作为日志系统,但是保持这些老代码继续不变地使用log4j来记录日志。这样我们就需要同时初始化logback和log4j。
       首先,你需要确保在pom.xml中,同时包含log4j和logback-classic这两个依赖,但是请一定不要包含slf4j-log4j12这个包,因为它会和logback-classic起冲突。

  
  
  
  
  1. <dependencies> 
  2.     <dependency> 
  3.         <groupId>org.slf4j</groupId> 
  4.         <artifactId>slf4j-api</artifactId> 
  5.     </dependency> 
  6.     <dependency> 
  7.         <groupId>org.slf4j</groupId> 
  8.         <artifactId>jcl-over-slf4j</artifactId> 
  9.     </dependency> 
  10.     <dependency> 
  11.         <groupId>ch.qos.logback</groupId> 
  12.         <artifactId>logback-classic</artifactId> 
  13.     </dependency> 
  14.     <dependency> 
  15.         <groupId>log4j</groupId> 
  16.         <artifactId>log4j</artifactId> 
  17.     </dependency> 
  18. </dependencies> 
  19. <dependencyManagement> 
  20.     <dependencies> 
  21.         <dependency> 
  22.             <groupId>org.slf4j</groupId> 
  23.             <artifactId>slf4j-api</artifactId> 
  24.             <version>1.6.1</version> 
  25.         </dependency> 
  26.         <dependency> 
  27.             <groupId>org.slf4j</groupId> 
  28.             <artifactId>jcl-over-slf4j</artifactId> 
  29.             <version>1.6.1</version> 
  30.         </dependency> 
  31.         <dependency> 
  32.             <groupId>commons-logging</groupId> 
  33.             <artifactId>commons-logging</artifactId> 
  34.             <version>1.1.1</version> 
  35.             <scope>provided</scope> 
  36.         </dependency> 
  37.         <dependency> 
  38.             <groupId>ch.qos.logback</groupId> 
  39.             <artifactId>logback-classic</artifactId> 
  40.             <version>0.9.28</version> 
  41.             <scope>runtime</scope> 
  42.         </dependency> 
  43.         <dependency> 
  44.             <groupId>log4j</groupId> 
  45.             <artifactId>log4j</artifactId> 
  46.             <version>1.2.16</version> 
  47.             <scope>runtime</scope> 
  48.         </dependency> 
  49.     </dependencies> 
  50. </dependencyManagement> 

 

你可能感兴趣的:(职场,logging,日志系统,休闲)