reidmorrison / rails_semantic_logger

Rails Semantic Logger replaces the Rails default logger with Semantic Logger
https://logger.rocketjob.io/rails
Apache License 2.0
329 stars 116 forks source link

Logs don't appear in test.log #130

Closed artemave closed 3 years ago

artemave commented 3 years ago

Environment

2.6.6p146

6.1.3

4.7.4

4.5.1

Puma: 5.3.1 Minitest: 5.14.4

Just requiring a gem. Plus conig.log_level = :debug.

Expected Behavior

Observing logs in log/test.log

Actual Behavior

I can only see these three lines when I run any test:

2021-05-20 09:58:43.739789 D [114153:47096068045160] (0.252ms) ActiveRecord -- { allocations: 12, binds: { key: "schema_sha1" }, cached: nil, sql: "SELECT \"ar_internal_metadata\".\"value\" FROM \"ar_internal_metadata\" WHERE \"ar_internal_metadata\".\"key\" = $1" }
2021-05-20 09:58:43.752974 D [114153:47096068045160] (0.380ms) ActiveRecord -- { allocations: 9, cached: nil, sql: "SELECT \"schema_migrations\".\"version\" FROM \"schema_migrations\" ORDER BY \"schema_migrations\".\"version\" ASC" }
2021-05-20 09:58:43.854755 I [114153:47096068045160] Rails -- Everything's up-to-date. Nothing to do
reidmorrison commented 3 years ago

In the documentation, when running Puma in clustered mode, add the following to config/puma.rb

on_worker_boot do
  ApplicationRecord.establish_connection if defined?(ActiveRecord)

  # Re-open appenders after forking the process
  SemanticLogger.reopen
end

Docs: https://logger.rocketjob.io/forking.html

reidmorrison commented 3 years ago

If running in a forked environment, such as parallel test you could just disable the use of the background thread for logging by calling: SemanticLogger.sync! before starting Rails or performing any other logging.

artemave commented 3 years ago

SemanticLogger.sync! did the trick - thanks!