Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to log queries on Neo4J like Hibernate?

So, here is the scenario:

  • I have Neo4J server running locally with some data in it
  • I have a web app using spring-data-neo4j

The following code is based on the example code Cineasts:

public interface CrewRepository extends GraphRepository<Crew> {

  Iterable<Crew> findByNameLike(String name);

  @Query("start thinker=node({0}) match thinker-[:crews]-crews return crews")
  Set<Crew> findByThinker(Long thinkerId);

}

No news here. The problem is: the query findByNameLike doesn't work whereas the findByThinker does.

I have modified my log configuration file many times - final version is the one below - but, doesn't matter what I try, I can't see any queries being logged - either on my log file or on the server.

<logger name="org.neo4j">
  <level value="DEBUG" />
  <appender-ref ref="console" />
</logger>

<logger name="org.springframework.data.neo4j">
  <level value="DEBUG" />
  <appender-ref ref="console" />
</logger>

<root>
  <priority value="error" />
  <appender-ref ref="console" />
</root>

All I want is the log the queries so I can see if it's a bug on spring-data-neo4j or if I'm missing something... I have looked through the documentation of both, code examples and couldn't find anything that specific.

Any help? Thank you!

like image 975
Tarcio Saraiva Avatar asked Jan 18 '23 17:01

Tarcio Saraiva


2 Answers

You can enable query logging by adding the following lines to your log4j.xml:

<logger name="org.springframework.data.neo4j.support.query">
    <level value="debug" />
</logger>
like image 163
Michael König Avatar answered Feb 14 '23 20:02

Michael König


If anyone lands here looking for how to log queries when Neo4j Server is accessed remotely over the REST API, use

<logger name="org.springframework.data.neo4j.rest.SpringRestCypherQueryEngine">
    <level value="debug" />
</logger>

If you're using Spring Data Neo4j and want to see the derived queries corresponding to your DAO methods,

<logger name="org.springframework.data.neo4j.repository.query.DerivedCypherRepositoryQuery">
    <level value="debug" />
</logger>
like image 23
Emerson Farrugia Avatar answered Feb 14 '23 21:02

Emerson Farrugia