Skip to content

Commit

Permalink
Improve Log-Handling in Bolt-, Embedded- and HttpRequest.
Browse files Browse the repository at this point in the history
- Logger is now static
- Statements and their parameters are only logged to debug

Closes #530.
  • Loading branch information
michael-simons authored and meistermeier committed Oct 10, 2018
1 parent 3e05ab2 commit f37a78e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
/**
* @author vince
* @author Luanne Misquitta
* @author Michael J. Simons
*/
public class BoltRequest implements Request {

private final TransactionManager transactionManager;

private static final ObjectMapper mapper = ObjectMapperFactory.objectMapper();
private static final Logger LOGGER = LoggerFactory.getLogger(BoltRequest.class);

private final Logger LOGGER = LoggerFactory.getLogger(BoltRequest.class);
private final TransactionManager transactionManager;

private TypeReference<HashMap<String, Object>> MAP_TYPE_REF = new TypeReference<HashMap<String, Object>>() {
};
Expand Down Expand Up @@ -151,11 +151,13 @@ private StatementResult executeRequest(Statement request) {
BoltTransaction tx;
try {
Map<String, Object> parameterMap = mapper.convertValue(request.getParameters(), MAP_TYPE_REF);
String statement = cypherModification.apply(request.getStatement());
LOGGER.info("Request: {} with params {}", statement, parameterMap);
String cypher = cypherModification.apply(request.getStatement());
if(LOGGER.isDebugEnabled()) {
LOGGER.debug("Request: {} with params {}", cypher, parameterMap);
}

tx = (BoltTransaction) transactionManager.getCurrentTransaction();
return tx.nativeBoltTransaction().run(statement, parameterMap);
return tx.nativeBoltTransaction().run(cypher, parameterMap);
} catch (ClientException | DatabaseException | TransientException ce) {
throw new CypherException("Error executing Cypher", ce, ce.code(), ce.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@
/**
* @author vince
* @author Luanne Misquitta
* @author Michael J. Simons
*/
public class EmbeddedRequest implements Request {

private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddedRequest.class);
private static final ObjectMapper mapper = ObjectMapperFactory.objectMapper();

private final GraphDatabaseService graphDatabaseService;
private final Logger logger = LoggerFactory.getLogger(EmbeddedRequest.class);
private final TransactionManager transactionManager;

private final TypeReference<HashMap<String, Object>> MAP_TYPE_REF = new TypeReference<HashMap<String, Object>>() {
Expand Down Expand Up @@ -122,7 +123,7 @@ public RowModel next() {
@Override
public void close() {
if (transactionManager.getCurrentTransaction() != null) {
logger.debug("Response closed: {}", this);
LOGGER.debug("Response closed: {}", this);
}
}

Expand All @@ -149,13 +150,14 @@ public Response<RestModel> execute(RestModelRequest request) {
return new RestModelResponse(executeRequest(request), transactionManager);
}

private Result executeRequest(Statement statement) {
private Result executeRequest(Statement request) {

try {
String cypher = cypherModification.apply(statement.getStatement());

Map<String, Object> parameterMap = mapper.convertValue(statement.getParameters(), MAP_TYPE_REF);
logger.info("Request: {} with params {}", cypher, parameterMap);
Map<String, Object> parameterMap = mapper.convertValue(request.getParameters(), MAP_TYPE_REF);
String cypher = cypherModification.apply(request.getStatement());
if(LOGGER.isDebugEnabled()) {
LOGGER.debug("Request: {} with params {}", cypher, parameterMap);
}

return graphDatabaseService.execute(cypher, parameterMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ private CloseableHttpResponse executeRequest(String cypher) throws HttpRequestEx
request.setEntity(new StringEntity(cypher, "UTF-8"));
request.setHeader("X-WRITE", readOnly ? "0" : "1");

LOGGER.info("Thread: {}, url: {}, request: {}", Thread.currentThread().getId(), url, cypher);
if(LOGGER.isDebugEnabled()) {
LOGGER.debug("Thread: {}, url: {}, request: {}", Thread.currentThread().getId(), url, cypher);
}

return execute(httpClient, request, credentials);
}
Expand Down

0 comments on commit f37a78e

Please sign in to comment.