Created
December 10, 2018 02:44
-
-
Save iamitshri/073e83ea85eb01143eae890961bf68e9 to your computer and use it in GitHub Desktop.
Using stopwatch from package org.apache.commons.lang3.time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.amit; | |
import org.apache.commons.lang3.time.StopWatch; | |
import lombok.extern.slf4j.Slf4j; | |
/** | |
* Hello world! | |
* | |
*/ | |
@Slf4j | |
public class App { | |
public static void main(String[] args) throws InterruptedException { | |
log.debug("Hello World!"); | |
StopWatch stopwatch = new StopWatch(); | |
stopwatch.start(); | |
Thread.sleep(1000l); | |
stopwatch.split(); | |
final long splitTime1 = stopwatch.getSplitTime(); | |
log.debug("time spent {}, split time:{}", stopwatch.toSplitString(), stopwatch.toSplitString()); | |
Thread.sleep(1000l); | |
stopwatch.split(); | |
log.debug("split time {}: Time since last split: {}", stopwatch.toSplitString(), | |
(stopwatch.getSplitTime() - splitTime1)); | |
Thread.sleep(1000l); | |
stopwatch.stop(); | |
log.debug("Total time spent {}", stopwatch.getTime()); | |
} | |
} |
log4j2.properties
name=PropertiesConfig
property.filename = logs
appenders = console, file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/propertieslogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
loggers=file
logger.file.name=guru.springframework.blog.log4j2properties
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pom.xml