Skip to content

Commit 76b0f8b

Browse files
committed
adding logging lib log4j2, to log test side log information
1 parent ecfeef6 commit 76b0f8b

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

test-complete/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ dependencies {
2222
compile('xmlunit:xmlunit:1.5')
2323
compile('junit:junit:4.11')
2424
compile('org.skyscreamer:jsonassert:1.2.3')
25+
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
26+
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
2527
}
2628

test-complete/src/test/java/com/marklogic/client/functionaltest/ConnectedRESTQA.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
import org.apache.http.NameValuePair;
3131
import org.apache.http.message.BasicNameValuePair;
3232
import org.apache.http.client.entity.*;
33+
import org.apache.logging.log4j.*;
3334

3435
import java.io.IOException;
3536
import java.io.InputStream;
37+
import java.util.Calendar;
38+
import java.util.Date;
3639
import java.util.Iterator;
3740
import java.util.List;
3841
import java.util.ArrayList;
@@ -53,6 +56,7 @@
5356

5457
import static org.junit.Assert.*;
5558

59+
5660
/**
5761
* @author gvaidees
5862
*
@@ -63,7 +67,10 @@ public abstract class ConnectedRESTQA {
6367
* Use Rest call to create a database.
6468
* @param dbName
6569
*/
70+
private static final Logger logger = LogManager.getLogger(ConnectedRESTQA.class);
71+
6672

73+
6774
public static void createDB(String dbName) {
6875
try {
6976

@@ -325,14 +332,26 @@ public static void createRESTServerWithDB(String restServerName,int restPort) {
325332
*
326333
*/
327334
public static void setupJavaRESTServer(String dbName, String fName, String restServerName, int restPort)throws Exception{
328-
335+
336+
337+
Calendar cal = Calendar.getInstance();
338+
Date d = cal.getTime();
339+
long before =cal.getTimeInMillis();
340+
logger.info("###Entering Application SETUP.###"+d);
329341
createDB(dbName);
330342
createForest(fName,dbName);
331343
Thread.sleep(1500);
332344
assocRESTServer(restServerName, dbName,restPort);
333345
createRESTUser("rest-admin","x","rest-admin");
334346
createRESTUser("rest-writer","x","rest-writer");
335347
createRESTUser("rest-reader","x","rest-reader");
348+
cal = Calendar.getInstance();
349+
long after =cal.getTimeInMillis();
350+
long diff = after - before;
351+
352+
String msg = "###Ending Application SETUP.###:"+diff/1000+" seconds";
353+
logger.info(msg);
354+
336355
}
337356
public static void setupJavaRESTServer(String dbName, String fName, String restServerName, int restPort,boolean attachRestContextDB)throws Exception{
338357

@@ -791,7 +810,11 @@ else if(response.getStatusLine().getStatusCode() == 200){
791810
* This function move rest server first to documents and deletes forests and databases in separate calls
792811
*/
793812
public static void tearDownJavaRESTServer(String dbName, String [] fNames, String restServerName) throws Exception{
794-
813+
Calendar cal = Calendar.getInstance();
814+
Date d = cal.getTime();
815+
long before =cal.getTimeInMillis();
816+
logger.info("###Entering Application Teardown.###"+d);
817+
795818
try{
796819
associateRESTServerWithDB(restServerName,"Documents");
797820
}catch(Exception e){
@@ -815,7 +838,14 @@ public static void tearDownJavaRESTServer(String dbName, String [] fNames, Strin
815838
e.printStackTrace();
816839
}
817840

818-
deleteDB(dbName);
841+
deleteDB(dbName);
842+
cal = Calendar.getInstance();
843+
long after =cal.getTimeInMillis();
844+
long diff = after - before;
845+
846+
String msg = "###Ending Application SETUP.###:-"+diff/1000+" seconds";
847+
logger.info(msg);
848+
819849
}
820850

821851

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration package="com.marklogic.client.functionaltest.ConnectedRESTQA" >
3+
<Appenders>
4+
5+
<File name="MyTestLogFile" fileName="./testLog/TestLogging.log">
6+
<PatternLayout>
7+
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
8+
</PatternLayout>
9+
</File>
10+
11+
</Appenders>
12+
<Loggers>
13+
<Root level="trace">
14+
<AppenderRef ref="MyTestLogFile"/>
15+
</Root>
16+
</Loggers>
17+
</Configuration>

0 commit comments

Comments
 (0)