Permalink
Browse files

Added slf4j logging. This resolves issue #47

  • Loading branch information...
tzaeschke committed May 26, 2017
1 parent 558f08b commit fbfbc4dcb0130e71a7237dfb3bea7f84a0315646
View
@@ -1,34 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" output="target/classes" path="src">
+ <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="tst">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
- <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="tst">
+ <classpathentry excluding="**" kind="src" output="target/classes" path="resources">
<attributes>
- <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
- <classpathentry excluding="**" kind="src" output="target/classes" path="examples">
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
- <classpathentry excluding="**" kind="src" output="target/classes" path="resources">
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <classpathentry kind="src" output="target/classes" path="examples">
<attributes>
+ <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <classpathentry kind="src" output="target/classes" path="src">
<attributes>
+ <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
View
@@ -6,7 +6,9 @@ CHANGELOG
- T.Zaeschke
- Fixed issue #98, problem with autocreation of schema with empty arrays.
- Fixed issue #99, problem with character values in queries
- - Fized issue #101, NPE with ZooCompareDB
+ - Fixed issue #101, NPE with ZooCompareDB
+ - Added slf4j logging, this solves issue #47
+ - API Change! DBLogger.setLoggerLevel has been removed. Instead, the slf4j logger should be used
2017-Apr-25
===========
View
89 pom.xml
@@ -51,11 +51,6 @@
</distributionManagement>
<dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- </dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
@@ -67,24 +62,76 @@
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+
+ <!-- Only for testing -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.25</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>tst</testSourceDirectory>
<resources>
- <resource>
- <directory>examples</directory>
- </resource>
<resource>
<directory>resources</directory>
</resource>
</resources>
- <plugins>
- <plugin>
+ <testResources>
+ <testResource>
+ <directory>tstresources</directory>
+ </testResource>
+ <testResource>
+ <directory>${project.basedir}/tst</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </testResource>
+ <testResource>
+ <!-- Add the default dir when overwriting testResource: -->
+ <directory>${project.basedir}/src/test/resources</directory>
+ </testResource>
+ </testResources>
+
+ <plugins>
+ <!-- To treat 'examples' as source folder -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>examples</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <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>
@@ -97,7 +144,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>2.9.1</version>
+ <version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
@@ -112,7 +159,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
+ <version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@@ -125,7 +172,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
- <version>1.5</version>
+ <version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
@@ -150,7 +197,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.15</version>
+ <version>2.20</version>
<configuration>
<argLine>${argLine} -Xmx512m</argLine>
<printSummary>true</printSummary>
@@ -193,18 +240,6 @@
</plugin>
</plugins>
- <testResources>
- <testResource>
- <directory>${project.basedir}/tst</directory>
- <excludes>
- <exclude>**/*.java</exclude>
- </excludes>
- </testResource>
- <testResource>
- <!-- Add the default dir when overwriting testResource: -->
- <directory>${project.basedir}/src/test/resources</directory>
- </testResource>
- </testResources>
</build>
</project>
@@ -28,14 +28,15 @@
import java.util.HashSet;
import java.util.Set;
import java.util.WeakHashMap;
-import java.util.logging.Level;
import javax.jdo.JDOOptimisticVerificationException;
import javax.jdo.ObjectState;
import javax.jdo.listener.DeleteCallback;
import javax.jdo.listener.InstanceLifecycleListener;
import javax.jdo.listener.StoreCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.zoodb.api.ZooInstanceEvent;
import org.zoodb.api.impl.ZooPC;
import org.zoodb.internal.client.SchemaManager;
@@ -61,6 +62,8 @@
*/
public class Session implements IteratorRegistry {
+ public static final Logger LOGGER = LoggerFactory.getLogger(Session.class);
+
public static final long OID_NOT_ASSIGNED = -1;
public static final long TIMESTAMP_NOT_ASSIGNED = -1;
@@ -102,8 +105,8 @@ public Session(SessionParentCallback parentSession, String dbPath, SessionConfig
this.nodes.add(primary);
this.cache.addNode(primary);
this.primary.connect();
- if (DBLogger.isLoggable(Level.FINE)) {
- DBLogger.LOGGER.fine("Session created (ihc=" + System.identityHashCode(this) + ")");
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("Session created (ihc={})", System.identityHashCode(this));
}
}
@@ -113,9 +116,7 @@ public boolean isActive() {
public void begin() {
try {
- if (DBLogger.isLoggable(Level.FINE)) {
- DBLogger.LOGGER.fine("begin(txId=" + transactionId + ")");
- }
+ LOGGER.info("begin(txId={})", transactionId);
lock();
checkOpen();
if (isActive) {
@@ -174,10 +175,7 @@ public void commit(boolean retainValues) {
schemaManager.postCommit();
} catch (RuntimeException e) {
try {
- if (DBLogger.isLoggable(Level.FINE)) {
- DBLogger.LOGGER.fine("commit(txId=" + transactionId +
- ") aborted, rolling back");
- }
+ LOGGER.info("commit(txId={}) aborted, rolling back", transactionId);
if (DBLogger.isUser(e)) {
//reset sinks
for (ZooClassDef cs: cache.getSchemata()) {
@@ -193,7 +191,7 @@ public void commit(boolean retainValues) {
} catch (Throwable t) {
//YES! Finally a good reason to swallow an exception.
//Exception 'e' is of course more important than 't', so we swallow it...
- DBLogger.severe("rollback() failed: " + t.getMessage());
+ LOGGER.error("rollback() failed: {}", t.getMessage());
t.printStackTrace();
}
throw e;
@@ -203,10 +201,9 @@ public void commit(boolean retainValues) {
isActive = false;
} finally {
unlock();
- if (DBLogger.isLoggable(Level.FINE)) {
+ if (LOGGER.isInfoEnabled()) {
long t2 = System.nanoTime();
- DBLogger.LOGGER.fine("commit(txId=" + transactionId +
- ") finished - Time=" + (t2-t1) + "ns");
+ LOGGER.info("commit(txId={}) finished - Time={}ns", transactionId, (t2-t1));
}
}
}
@@ -371,9 +368,7 @@ private void commitInternal() {
public void rollback() {
try {
- if (DBLogger.isLoggable(Level.FINE)) {
- DBLogger.LOGGER.fine("rollback(txId=" + transactionId + ")");
- }
+ LOGGER.info("rollback(txId={})", transactionId);
lock();
checkActive();
rollbackInteral();
@@ -768,9 +763,7 @@ public void close() {
} finally {
unlock();
}
- if (DBLogger.isLoggable(Level.FINE)) {
- DBLogger.LOGGER.fine("Session closed (ihc=" + System.identityHashCode(this) + ")");
- }
+ LOGGER.info("Session closed (ihc={})", System.identityHashCode(this));
}
private void closeInternal() {
@@ -174,10 +174,10 @@ public void rollback() {
go.jdoZooMarkHollow();
}
dirtyGenObjects.clear();
- if (DBLogger.isLoggable(Level.FINE)) {
+ if (Session.LOGGER.isInfoEnabled()) {
int logSizeObjAfter = objs.size();
- DBLogger.LOGGER.fine("ClientCache.rollback() - Cache size before/after: " +
- logSizeObjBefore + "/" + logSizeObjAfter);
+ Session.LOGGER.info("ClientCache.rollback() - Cache size before/after: {} / {}",
+ logSizeObjBefore, logSizeObjAfter);
}
}
@@ -349,11 +349,11 @@ public void postCommit(boolean retainValues, boolean detachAllOnCommit) {
cs.jdoZooMarkClean(); //TODO remove if cache is flushed -> retainValues!!!!!
}
- if (DBLogger.isLoggable(Level.FINE)) {
+ if (Session.LOGGER.isInfoEnabled()) {
int logSizeObjAfter = objs.size();
long t2 = System.nanoTime();
- DBLogger.LOGGER.fine("ClientCache.postCommit() -- Time=" + (t2-t1) +
- "ns; Cache size before/after: " + logSizeObjBefore + "/" + logSizeObjAfter);
+ Session.LOGGER.info("ClientCache.postCommit() -- Time= {} ns; Cache size before/after: {} / {}",
+ (t2-t1), logSizeObjBefore, logSizeObjAfter);
}
}
@@ -35,6 +35,7 @@
import org.zoodb.internal.query.QueryParser.FNCT_OP;
import org.zoodb.internal.server.index.BitTools;
import org.zoodb.internal.util.DBLogger;
+import org.zoodb.jdo.impl.QueryImpl;
public class QueryOptimizer {
@@ -395,7 +396,7 @@ private void determineIndexToUseSubForQueryFunctions(
//if we have a regex that does not simply result in full match we
//simply use the leading part for a startsWith() query.
if (i == 0) {
- DBLogger.info("Ignoring index on String query because of regex characters.");
+ QueryImpl.LOGGER.info("Ignoring index on String query because of regex characters.");
}
str = str.substring(0, i);
setKeysForStringStartsWith(str, f, minMap, maxMap);
@@ -25,6 +25,8 @@
import java.nio.file.Path;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.zoodb.internal.Node;
import org.zoodb.internal.client.AbstractCache;
import org.zoodb.internal.server.DiskIO.PAGE_TYPE;
@@ -41,6 +43,8 @@
*/
class SessionManager {
+ public static final Logger LOGGER = LoggerFactory.getLogger(SecurityManager.class);
+
private static final long ID_FAULTY_PAGE = Long.MIN_VALUE;
private final FreeSpaceManager fsm;
@@ -111,7 +115,7 @@ public SessionManager(Path path) {
}
if (r0 == ID_FAULTY_PAGE && r1 == ID_FAULTY_PAGE) {
String m = "Database is corrupted and cannot be recoverd. Please restore from backup.";
- DBLogger.severe(m);
+ LOGGER.error(m);
throw DBLogger.newFatal(m);
}
@@ -200,8 +204,8 @@ private long checkRoot(StorageChannelInput in, int pageId) {
if (txID1 == txID2) {
return txID1;
}
- DBLogger.severe("Main page is faulty: " + pageId + ". Will recover from previous " +
- "page version.");
+ LOGGER.error("Main page is faulty: {}. Will recover from previous " +
+ "page version.", pageId);
return ID_FAULTY_PAGE;
}
Oops, something went wrong.

0 comments on commit fbfbc4d

Please sign in to comment.