No db logging in test suite

Hey :wave:,

I can’t get the DB logging to work in the test suite.

Here’s what I tried:

RSpec.configure do |config|
  config.before :suite do
    Hanami.app.start :db_logging
    Hanami.app.start :db
  end
end

Do you know what I’m doing wrong? The tests with db-contact run, but I see no SQL-logs.

Thanks

Oh, after adding this line of code at config/app.rb it works.

    # ...
    environment(:test) do
      config.logger.stream = $stdout
    end
    # ....

Have you tried tailing log/test.log? If it’s not writing to stdout then I would expect it defaults to the filesystem.

@alassek is on the right track here. By default in test mode, we log to log/test.log. This is to ensure we don’t pollute your test output with tons of log lines.

We log to stdout by default for the other modes: development and production.

If you’re interested, you can see the code here:

# Inside Hanami::Config::Logger

        case env
        when :development, :test
          config.level = :debug
          config.stream = File.join("log", "#{env}.log") if env == :test
          config.logger_constructor = method(:development_logger)
        else
          config.level = :info
          config.formatter = :json
          config.logger_constructor = method(:production_logger)
        end

Let us know if you have any other feedback about this, @wuarmin!

This could be an opportunity to update our docs, too. If you find a got spot to put this information, I’d be happy to work with you on a PR :slight_smile:

Thanks!