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

Adding gem changes global logging settings. #2

Open
danwakefield opened this issue Mar 31, 2022 · 0 comments
Open

Adding gem changes global logging settings. #2

danwakefield opened this issue Mar 31, 2022 · 0 comments

Comments

@danwakefield
Copy link

danwakefield commented Mar 31, 2022

  • Rails version: 5.1.7
  • Typesense Rails integration version: adapation
  • Typesense Client Version: 0.13.0
  • Language Version: 2.7.2

Description

Typesense shouldn't affect logging from migrate tasks / specs

Steps To Reproduce

rbenv local 2.7.2
rails _5.1.7_ new foo
cd foo
rails g model Bar
rails db:migrate

Output of migrate

== 20220331123536 CreateBars: migrating =======================================
-- create_table(:bars)
   -> 0.0003s
== 20220331123536 CreateBars: migrated (0.0003s) ==============================

Then

rails db:drop
echo "gem 'typesense-rails', git: 'https://github.com/typesense/typesense-rails.git', branch: 'adaptation'" >> Gemfile
bundle install
rails db:migrate

Output of migrate

   (0.0ms)  SELECT sqlite_version(*)
   (1.0ms)  CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
   (0.5ms)  CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
   (0.0ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Migrating to CreateBars (20220331123536)
   (0.0ms)  begin transaction
== 20220331123536 CreateBars: migrating =======================================
-- create_table(:bars)
   (0.2ms)  CREATE TABLE "bars" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
   -> 0.0003s
== 20220331123536 CreateBars: migrated (0.0003s) ==============================

  SQL (0.0ms)  INSERT INTO "schema_migrations" ("version") VALUES (?)  [["version", "20220331123536"]]
   (0.3ms)  commit transaction
  ActiveRecord::InternalMetadata Load (0.0ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?  [["key", "environment"], ["LIMIT", 1]]
   (0.0ms)  begin transaction
  SQL (0.1ms)  INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["key", "environment"], ["value", "development"], ["created_at", "2022-03-31 12:42:21.424311"], ["updated_at", "2022-03-31 12:42:21.424311"]]
   (0.2ms)  commit transaction
   (0.0ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC

I think this should be done in the railtie / engine rather than top level of the file.

This also changes the logging setting when running specs.

https://github.com/typesense/typesense-rails/blob/adaptation/lib/typesense-rails.rb#L20-L22

Edit: Some further investigation shows that we were getting the logger defined in

https://github.com/rails/rails/blob/5-1-stable/railties/lib/rails/application/bootstrap.rb#L33

We are currently handling this by changing config/environment.rb to unset loggers set before the application is initialized

require_relative 'application'

Rails.logger = nil
Rails.application.initialize!
@danwakefield danwakefield changed the title Adding gem changes logging setting for rake tasks. Adding gem changes global logging settings. Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant