BAEL-3321 Flogger Fluent Logging (#7872)
* Added Flogger maven dependency * Implemented Flogger logging examples * Finished implementing Flogger logging examples * Changed Flogger Test to Integration tests * Adding examples on optimisation * Added support for Slf4j and Log4j backends * Added support for Slf4j and Log4j backends, uncommended dependencies in pom, removed log4j config file
This commit is contained in:
		
							parent
							
								
									0a67756dee
								
							
						
					
					
						commit
						6f9c339986
					
				| @ -17,11 +17,50 @@ | ||||
|             <artifactId>flogger</artifactId> | ||||
|             <version>0.4</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>com.google.flogger</groupId> | ||||
|             <artifactId>flogger-system-backend</artifactId> | ||||
|             <version>0.4</version> | ||||
|             <scope>runtime</scope> | ||||
|         </dependency> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>com.google.flogger</groupId> | ||||
|             <artifactId>flogger-slf4j-backend</artifactId> | ||||
|             <version>0.4</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>com.google.flogger</groupId> | ||||
|             <artifactId>flogger-log4j-backend</artifactId> | ||||
|             <version>0.4</version> | ||||
|             <exclusions> | ||||
|                 <exclusion> | ||||
|                     <groupId>com.sun.jmx</groupId> | ||||
|                     <artifactId>jmxri</artifactId> | ||||
|                 </exclusion> | ||||
|                 <exclusion> | ||||
|                     <groupId>com.sun.jdmk</groupId> | ||||
|                     <artifactId>jmxtools</artifactId> | ||||
|                 </exclusion> | ||||
|                 <exclusion> | ||||
|                     <groupId>javax.jms</groupId> | ||||
|                     <artifactId>jms</artifactId> | ||||
|                 </exclusion> | ||||
|             </exclusions> | ||||
|         </dependency> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>log4j</groupId> | ||||
|             <artifactId>log4j</artifactId> | ||||
|             <version>1.2.17</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>log4j</groupId> | ||||
|             <artifactId>apache-log4j-extras</artifactId> | ||||
|             <version>1.2.17</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|     </dependencies> | ||||
| </project> | ||||
| @ -12,6 +12,10 @@ import java.util.stream.IntStream; | ||||
| import static com.google.common.flogger.LazyArgs.lazy; | ||||
| 
 | ||||
| public class FloggerIntegrationTest { | ||||
|     static { | ||||
| //        System.setProperty("flogger.backend_factory", "com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"); | ||||
|         System.setProperty("flogger.backend_factory", "com.google.common.flogger.backend.slf4j.Slf4jBackendFactory#getInstance"); | ||||
|     } | ||||
|     private static final FluentLogger logger = FluentLogger.forEnclosingClass(); | ||||
| 
 | ||||
|     @Test | ||||
| @ -28,6 +32,16 @@ public class FloggerIntegrationTest { | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenAnObject_shouldLogTheObject() { | ||||
|         User user = new User(); | ||||
|         logger.atInfo().log("The user is: %s", user); //correct | ||||
| 
 | ||||
|         //The following ways of logging are not recommended | ||||
|         logger.atInfo().log("The user is: %s", user.toString()); | ||||
|         logger.atInfo().log("The user is: %s" + user); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenASimpleOperation_shouldLogTheResult() { | ||||
|         int result = 45 / 3; | ||||
| @ -70,4 +84,13 @@ public class FloggerIntegrationTest { | ||||
|         int s = 30; | ||||
|         return String.format("%d seconds elapsed so far. %d items pending processing", s, items); | ||||
|     } | ||||
| 
 | ||||
|     private class User { | ||||
|         String name = "Test"; | ||||
| 
 | ||||
|         @Override | ||||
|         public String toString() { | ||||
|             return name; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user