Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to control production DB log #607

Open
ablce9 opened this issue Jan 4, 2021 · 1 comment
Open

Unable to control production DB log #607

ablce9 opened this issue Jan 4, 2021 · 1 comment
Labels

Comments

@ablce9
Copy link

ablce9 commented Jan 4, 2021

The db log is always logged and we'd like to make it go away at production environment. Looked through documentations and source code and finally reached this PR. I reckon no options available to disable SQL logging?
I worked on a few hours and found a workaround that is:

# config/initializers/models.rb
unless Hanami.env?(:development)
  Hanami::Model.configuration.connection.loggers = []
end

The solution worked.

Is this a legit solution to disable log? This issue should be tagged as question.

Tried following but nothing seems effective

# config/environment.rb
  model do
    adapter :sql, ENV.fetch('DATABASE_URL') 

    gateway do |g|
      g.use_logger(Hanami::Logger.new(nil, '/dev/null'))
      g.connection.loggers = []
    end

    logger '/dev/null'

    ##
    # Migrations
    #
    migrations 'db/migrations'
    schema     'db/schema.sql'
  end
@skcc321
Copy link

skcc321 commented Jul 8, 2021

I faced with a similar problem - I expected changing log_level to "info" should disable SQL logs (similar to Rails logger) but it just does not work. When I change the log level to "warn" - SQL logs disappear. So I think the problem is in SQL logs level as well.
I found this line https://github.com/jeremyevans/sequel/blob/master/lib/sequel/database/logging.rb#L22 which seems not fine for those who are familiar with Rails logger.
In general, I like that Hanami supports JSON logs formatter which is not supported natively by Rails, but I would like to have some kind of match between SQL log levels (opportunity of logger configuration like described above is something important as well)
here is my solution:

# /initializers/sequel.rb
Hanami::Model.configuration.connection.sql_log_level = :debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants