Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<groupId>org.jdbcdslog</groupId>
<artifactId>jdbcdslogexp2</artifactId>
<version>2.2-SNAPSHOT</version>
<version>2.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JDBC DS Log - EXP v2</name>
<url>https://github.com/adrianshum/jdbcdslog/</url>
Expand Down Expand Up @@ -75,29 +75,28 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.5</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<version>1.7.36</version>
<scope>compile</scope>
</dependency>

<!-- test scope -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<version>1.6.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<version>1.2.17</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -122,14 +121,14 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.0</version>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -145,10 +144,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.10.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
<fork>true</fork>
<compilerVersion>1.5</compilerVersion>
Expand Down Expand Up @@ -182,7 +181,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -199,7 +198,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -216,7 +215,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/jdbcdslog/ConfigurationParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class ConfigurationParameters {

static long slowQueryThresholdInNano = Long.MAX_VALUE;
static Boolean showTime = false;
static Boolean showTimeInNewLine = true;
static Boolean formatTimeInMs = false;
static boolean printStackTrace = false;
static boolean printFullStackTrace = false;
static String printStackTracePattern = null;
Expand All @@ -40,6 +42,8 @@ public class ConfigurationParameters {
initPrintFullStackTrace();
initPrintStackTracePattern();
initShowTime();
initFormatTimeInMs();
initShowTimeInNewLine();
initInlineQueryParams();
initRdbmsSpecifics();
initLogBeforeStatement();
Expand Down Expand Up @@ -102,6 +106,14 @@ private static void initShowTime() {
showTime = "true".equalsIgnoreCase(props.getProperty("jdbcdslog.showTime", "false"));
}

private static void initShowTimeInNewLine() {
showTimeInNewLine = "true".equalsIgnoreCase(props.getProperty("jdbcdslog.showTimeInNewLine", "true"));
}

private static void initFormatTimeInMs() {
formatTimeInMs = "true".equalsIgnoreCase(props.getProperty("jdbcdslog.formatTimeInMs", "false"));
}

private static void initInlineQueryParams() {
inlineQueryParams = ("true".equalsIgnoreCase(props.getProperty("jdbcdslog.inlineQueryParams", "true"))) ;
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/jdbcdslog/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,21 @@ public static void handleException(Throwable e, Logger l, StringBuilder msg) thr
*/
public static StringBuilder appendElapsedTime(StringBuilder sb, long elapsedTimeInNano) {
if (ConfigurationParameters.showTime) {
sb.append("\nElapsed Time: ").append(String.format("%.9f", elapsedTimeInNano/1000000000.0)).append(" s.");

if (ConfigurationParameters.showTimeInNewLine) {
sb.append("\n");
} else {
sb.append(" ");
}

sb.append("Elapsed Time: ");
if (ConfigurationParameters.formatTimeInMs) {
sb.append(String.format("%.0f", elapsedTimeInNano/1000000.0)).append(" ms.");
} else {
sb.append(String.format("%.9f", elapsedTimeInNano/1000000000.0)).append(" s.");
}
}
return sb;

}

public static String appendStackTrace(String message) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/jdbcdslog/LogUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.jdbcdslog;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.lang.reflect.Method;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Properties;
import java.util.TreeMap;

import org.junit.Ignore;
Expand Down Expand Up @@ -38,6 +41,31 @@ public void testOracleCreateLogEntry() {
sb.toString());
}

@Test
public void testElapseTimeDefault() {

String result = String.format("%.0f", (double)7381589601L / 1000000L);

// String result = String.format("%.6f", (long)7381589601L / 1000000000);
System.out.println(result);


StringBuilder sb = new StringBuilder();
sb = LogUtils.appendElapsedTime(sb, 7381589601L);
assertEquals(sb.toString(), "\n" + "Elapsed Time: 7.381589601 s.");
}

@Test
public void testElapseTimeShowInNewLine_default() {

// WHEN
StringBuilder sb = new StringBuilder();
sb = LogUtils.appendElapsedTime(sb, 7381589601L);

// THEN
assertEquals(sb.toString(), "\nElapsed Time: 7.381589601 s.");
}

@Test
public void testOracleCreateLogEntryWithFourParamsCase1() throws Exception {
Method method = LogUtilsTest.class.getMethod("testOracleCreateLogEntryWithFourParamsCase1");
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/jdbcdslog.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ jdbcdslog.printStackTrace=true
#jdbcdslog will show elapsed time
jdbcdslog.showTime=true

# logs the timevalue in a new line (default is true)
jdbcdslog.showTimeInNewLine=true

# time is logged in milliseconds (default is seconds)
jdbcdslog.formatTimeInMs=false

#jdbcdslog driver name.if empty,is oracle(default db)
#you may choose "oracle","mysql" ,"sqlserver" or empty (Case-insensitive and does not need the double quotes)
jdbcdslog.driverName=oracle