activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

how to bypass cypher logging

Open ahmetkizilay opened this issue 8 years ago • 17 comments

Fix query logging so that by default it only outputs to the user in the console and development server. Logger can be changed with neo4j.config.logger configuration option.

I would like to disable cypher output in my production.log file. Can you elaborate on what configuration I should use to disable printing cypher strings?

I tried a several combination of config.neo4j.logger = nil but nothing seemed to work.

thanks

ahmetkizilay avatar Sep 09 '15 10:09 ahmetkizilay

How about this?

config.neo4j.logger  = Logger.new("/dev/null")

That said, you shouldn't need to disable the query logging in the production log. I thought I had set it up so that that wouldn't happen... Let me know if the above works, but I'd also like to take a look at that issue as well

cheerfulstoic avatar Sep 09 '15 10:09 cheerfulstoic

hi,

Thanks for the suggestion. Using dev null disables the output (in my development environment).

Currently we are using neo4j-5.2.3 gem in production setting, but I still see cypher info logging in the production.log file (without any additional config).

ahmetkizilay avatar Sep 09 '15 10:09 ahmetkizilay

I also just changed the logging to log at debug rather than info in 5.2.4. So if you set config.log_level = :info that should do it. Does that help?

I'm actually really puzzled by why the default config.log_level in the generated config/environments/production.rb is :debug. Any idea why that is?

cheerfulstoic avatar Sep 10 '15 23:09 cheerfulstoic

As stated in the Rails guides, Rails 5 will have :debug log level by default, so they changed to that somewhere between Rails 4.1.8 and 4.2.0.

dapicester avatar Dec 07 '15 07:12 dapicester

Interesting, if it's a change in Rails 5 why would it be in 4.1.x?

cheerfulstoic avatar Dec 07 '15 13:12 cheerfulstoic

I'm not sure where I copied the code from, but I had the following line which was also printing the cypher queries. Not strictly related to logging, but a headache when you think it is.

Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query(&method(:puts))

Remove that line and it stops.

jonblack avatar Mar 22 '17 15:03 jonblack

The problem is that if you're using Rails logging is set up for you in some cases here:

https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/railtie.rb#L129

So I was wondering if something got messed up with that

cheerfulstoic avatar Mar 22 '17 19:03 cheerfulstoic

I'm not using rails. My issue was the subscription to query and printing which I copied from somewhere without knowing it.

jonblack avatar Mar 23 '17 10:03 jonblack

I'm also having this issue.

I'm running RSpec tests with guard in a docker container interactively for a Rails 5 project.

I have tried the following configurations in config/environments/test.rb

config.neo4j.logger = nil
config.neo4j.logger = ActiveSupport::Logger.new('/dev/null')
Neo4j::Config[:logger] = ActiveSupport::Logger.new('/dev/null')
config.log_level = :warn

But test output is 400+ lines of Cipher queries every time.

kyle-rader avatar Jul 28 '17 23:07 kyle-rader

Can you share an example of the logging? I think that when we switched over to using the typhoeus plugin for faraday that extra stuff was being outputted, and that's probably not configured to output via the config.neo4j.logger

cheerfulstoic avatar Jul 29 '17 00:07 cheerfulstoic

In case that is it, it does seem like maybe the typhoeus gem enables logging unless the VERBOSE_SERVER environment variable is set. See this line. That might not be the code at all, though

cheerfulstoic avatar Jul 29 '17 00:07 cheerfulstoic

Actually, it looks like it's the ethon gem under the covers, so probably you can do Ethon.logger = <whatever>

cheerfulstoic avatar Jul 29 '17 00:07 cheerfulstoic

Here is an example of the output:

[1] guard(main)> 
00:14:01 - INFO - Run all
00:14:01 - INFO - Running all specs
Running via Spring preloader in process 32

Randomized with seed 40722
 CYPHER CALL db.constraints() 
 CYPHER CALL db.indexes() 
 CYPHER CREATE CONSTRAINT ON ( `neo4j::migrations::schemamigration`:`Neo4j::Migrations::SchemaMigration` ) ASSERT `neo4j::migrations::schemamigration`.migration_id IS UNIQUE 
 CYPHER CREATE CONSTRAINT ON ( page:Page ) ASSERT page.facebook_page_id IS UNIQUE 
 CYPHER CREATE CONSTRAINT ON ( page:Page ) ASSERT page.uuid IS UNIQUE 
 CYPHER CREATE CONSTRAINT ON ( post:Post ) ASSERT post.facebook_post_id IS UNIQUE 
 CYPHER CREATE CONSTRAINT ON ( post:Post ) ASSERT post.uuid IS UNIQUE 
 Neo4j::Migrations::SchemaMigration 
  MATCH (n:`Neo4j::Migrations::SchemaMigration`)
  RETURN n 
 CYPHER 
  WITH {versions} AS versions
  UNWIND versions AS version
  MERGE (:`Neo4j::Migrations::SchemaMigration` {migration_id: version}) | {:versions=>["20170719235456", "20170719235506", "20170720000928", "20170720000939"]}
........... CYPHER CREATE (n:`Page`) SET n = {props} RETURN n | {:props=>{:uuid=>"9c61859f-a431-430b-b022-c5c81cf6d5b6", :created_at=>1501287244, :updated_at=>1501287244, :facebook_page_id=>"489994737821093"}}
 CYPHER 
  MATCH (n:`Page`)
  RETURN count(n) AS count 
 Page 
  MATCH (n:`Page`)
  WHERE (n.facebook_page_id = {n_facebook_page_id})
  RETURN n
  LIMIT {limit_1} | {:n_facebook_page_id=>"489994737821093", :limit_1=>1}
 Post 
  MATCH (n:`Post`)
  WHERE (n.facebook_post_id = {n_facebook_post_id})
  RETURN n
  LIMIT {limit_1} | {:n_facebook_post_id=>"12345_6789", :limit_1=>1}
 CYPHER CREATE (n:`Post`) SET n = {props} RETURN n | {:props=>{:uuid=>"90bc1b0d-fd7a-485d-a379-ffdf4a95bf4c", :created_at=>1501287244, :updated_at=>1501287244, :facebook_post_id=>"12345_6789"}}
 CYPHER 
  MATCH 
    (from_node), 
    (to_node)
  WHERE 
    (ID(from_node) = {from_node_id}) AND 
    (ID(to_node) = {to_node_id})
  CREATE (from_node)-[rel:`shared` {rel_create_props}]->(to_node)
  SET rel.`created_at` = {setter_rel_created_at}, 
    rel.`updated_at` = {setter_rel_updated_at}
  RETURN rel | {:from_node_id=>4, :to_node_id=>5, :setter_rel_created_at=>1501287244, :setter_rel_updated_at=>1501287244, :rel_create_props=>{}}
 CYPHER 
  MATCH 
    (from_node), 
    (to_node)
  WHERE 
    (ID(from_node) = {from_node_id}) AND 
    (ID(to_node) = {to_node_id})
  CREATE (from_node)-[rel:`upvoted` {rel_create_props}]->(to_node)
  SET rel.`created_at` = {setter_rel_created_at}, 
    rel.`updated_at` = {setter_rel_updated_at}
  RETURN rel | {:from_node_id=>4, :to_node_id=>5, :setter_rel_created_at=>1501287244, :setter_rel_updated_at=>1501287244, :rel_create_props=>{}}
 CYPHER 
  MATCH (n:`Page`)
  RETURN count(n) AS count 
 CYPHER MATCH (n) DETACH DELETE n 

kyle-rader avatar Jul 29 '17 00:07 kyle-rader

The Ethon Gem also looks to be using the Rails logger if possible

kyle-rader avatar Jul 29 '17 00:07 kyle-rader

As far as I can tell, what you're doing should work to hide logs... The only thing I can think of is it any logger is set in config/application.rb or globally somewhere via Neo4j::Config[:logger]

If you do a bundle open neo4j it should allow you to edit your local installation of the neo4j gem and you could put a byebug / binding.pry in before this line to see what's going on (keep in mind that you might need to run spring stop if you use spring to make Rails see the changes to the gem)

cheerfulstoic avatar Jul 29 '17 00:07 cheerfulstoic

Thanks for the tips @cheerfulstoic I'll dig in more over the weekend. I'm also interested in implementing TLS for Bolt. I'll comment again when I've found out more. Happy Friday! -KR

kyle-rader avatar Jul 29 '17 00:07 kyle-rader

My solution:

  1. Add 'gem ethon' to your Gemfile. (If you don't do this, you will get 'uninitialized constant Ethon' in step 3.)

  2. Add the following to config/environments/production.rb:

config.log_level = :info

  1. Add the following to config/application.rb:
    neolog = Logger.new("#{Rails.root}/log/neo.log")
    config.neo4j.logger = neolog
    Ethon.logger = neolog

Result: You won't see any of the Neo4j debug logging in prod. In dev and staging, it will be routed to a separate file, neo.log. You can access it if you need it, but it won't turn your regular log file into a swamp of "ETHON: performed EASY effective_url=..." and Cypher statements.

EvanGranthamBrown avatar Jan 17 '19 21:01 EvanGranthamBrown