2

The SemanticLogger v4.4.0 gem was added to the repository, and now when using the rails console all the ActiveRecord queries are gone:

before:

> MyModel.last
  MyModel Load (3.4ms)  SELECT  `my_models`.* FROM `my_models`  ORDER BY `my_models`.`id` DESC LIMIT 1
=> #<MyModel:0x00007ff 
  id: ...

after:

> MyModel.last
=> #<MyModel:0x00007ff
  id: ...

I tried different setup flags for SemanticLogger but haven't found the one that returns the queries as before, and now is more complicated to detect poorly performance queries.

As a "partial-fix" I currently add it in a group and skipped develop:

gem 'rails_semantic_logger', group: %i[production qa]

This works on my local but I wish I could make it work on all environments.

2 Answers 2

3

It depends on the semantic_logger configuration but you should try

SemanticLogger.default_level = :trace

(you can run it in the console, and if works - add it to your initializers/development.rb or local.rb)

In my case I'd now see the output, but as a JSON:

> 2020-02-26 11:26:24.094050 D [2220:11016600] (220.0ms) ActiveRecord -- 
{ :sql => "SELECT COUNT(*) FROM \"things\"" }

So I need to add in my local.rb (not sure how this can be done dynamically in the console)

Rails.application.configure do
  config.rails_semantic_logger.semantic = false
end

to see

2020-02-26 11:31:34.972958 D [6280:14940580] ActiveRecord::Base --
    (198.6ms)  SELECT COUNT(*) FROM "things"
Sign up to request clarification or add additional context in comments.

Comments

1

SemanticLogger.default_level = :trace didn't help for me in console.

And I found this issue: https://github.com/reidmorrison/rails_semantic_logger/issues/83

2 Comments

you need to tail the log and is there, it not great, I ended up setting a env variable flag to enable/disable the gem on development
@zetacu I've added config.semantic_logger.add_appender to STDOUT, as described in the mentioned issue, inside Rails.application.console do. I can attach a code snippet to my answer if you want to, but it seems pretty simply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.