Skip to content

Commit

Permalink
[orientdb] adding slf4j logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kruthar committed Jan 18, 2016
1 parent 942c46a commit 04f109f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions orientdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ LICENSE file.
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
17 changes: 11 additions & 6 deletions orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -70,6 +72,8 @@ public class OrientDBClient extends DB {

private static final String ORIENTDB_DOCUMENT_TYPE = "document";

private final Logger log = LoggerFactory.getLogger(getClass());

@Override
public void init() throws DBException {
Properties props = getProperties();
Expand All @@ -86,7 +90,7 @@ public void init() throws DBException {
throw new DBException(String.format("Required property \"%s\" missing for OrientDBClient", URL_PROPERTY));
}

System.err.println("OrientDB loading database url = " + url);
log.info("OrientDB loading database url = " + url);

// If using a remote database, use the OServerAdmin interface to connect
if (url.startsWith(OEngineRemote.NAME)) {
Expand All @@ -101,12 +105,12 @@ public void init() throws DBException {

if (server.existsDatabase()) {
if (newdb && !dotransactions) {
System.err.println("OrientDB dropping and recreating fresh db on remote server.");
log.info("OrientDB dropping and recreating fresh db on remote server.");
server.dropDatabase(remoteStorageType);
server.createDatabase(server.getURL(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
}
} else {
System.err.println("OrientDB database not found, creating fresh db");
log.info("OrientDB database not found, creating fresh db");
server.createDatabase(server.getURL(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
}

Expand All @@ -121,20 +125,20 @@ public void init() throws DBException {
if (db.exists()) {
db.open(user, password);
if (newdb && !dotransactions) {
System.err.println("OrientDB dropping and recreating fresh db.");
log.info("OrientDB dropping and recreating fresh db.");
db.drop();
db.create();
}
} else {
System.err.println("OrientDB database not found, creating fresh db");
log.info("OrientDB database not found, creating fresh db");
db.create();
}
} catch (ODatabaseException e) {
throw new DBException(String.format("Error interfacing with %s", url), e);
}
}

System.err.println("OrientDB connection created with " + url);
log.info("OrientDB connection created with " + url);
dictionary = db.getMetadata().getIndexManager().getDictionary();
if (!db.getMetadata().getSchema().existsClass(CLASS)) {
db.getMetadata().getSchema().createClass(CLASS);
Expand Down Expand Up @@ -226,6 +230,7 @@ public Status scan(String table, String startkey, int recordcount, Set<String> f
Vector<HashMap<String, ByteIterator>> result) {
if (isRemote) {
// Iterator methods needed for scanning are Unsupported for remote database connections.
log.warn("OrientDB scan operation is not implemented for remote database connections.");
return Status.NOT_IMPLEMENTED;
}

Expand Down
8 changes: 8 additions & 0 deletions orientdb/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Root logger option
log4j.rootLogger=INFO, stderr

# Direct log messages to stderr
log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.Target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

0 comments on commit 04f109f

Please sign in to comment.