Skip to content

Instantly share code, notes, and snippets.

@vikmalik
Created December 11, 2012 18:11
Learn Logging in Java
package learn.java.logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LearnApacheLogging {
private static final Logger logger = LogManager.getLogger(LearnApacheLogging.class.getName());
public static void main(String[] args){
logger.fatal("Case 1: Start time : {}", System.currentTimeMillis());
for (int i = 0; i < 100000; i++) {
logger.debug("Entry number: {} is ", i);
}
logger.fatal("Case 1: End time : {}", System.currentTimeMillis());
logger.fatal("Case 2: Start time : {}", System.currentTimeMillis());
for (int i = 0; i < 100000; i++) {
if(logger.isDebugEnabled()){
logger.debug("Entry number: {} is ", i);
}
}
logger.fatal("Case 2: End time : {}", System.currentTimeMillis());
logger.fatal("Case 3: Start time : {}", System.currentTimeMillis());
for (int i = 0; i < 100000; i++) {
logger.debug("Entry number: " + i + " is ");
}
logger.fatal("Case 3: End time : {}", System.currentTimeMillis());
logger.fatal("Case 4: Start time : {}", System.currentTimeMillis());
for (int i = 0; i < 100000; i++) {
logger.debug("Static Log");
}
logger.fatal("Case 4: End time : {}", System.currentTimeMillis());
logger.fatal("Case 5: Start time : {}", System.currentTimeMillis());
for (int i = 0; i < 100000; i++) {
if(logger.isDebugEnabled()){
logger.debug("Static Log");
}
}
logger.fatal("Case 5: End time : {}", System.currentTimeMillis());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment