2017-04-04 5 views
0

私はRailsにログインして遊んでいましたが、私は奇妙なことに気付きました。
私が最初に理解しようとした質問は、ActiveRecordがSQLクエリをコンソールに記録する方法でした。Rails.logger神秘的な振る舞い

irb(main):001:0> Message.last 
    Message Load (7.4ms) SELECT "messages".* FROM "messages" ORDER BY "messages"."id" DESC LIMIT 1 

出力がhereであることがわかりました。 しかし、ActiveRecord::Base.logger#debugはどのようにしてSTDOUTlog/development.logに印刷されるのですか?

新しいRails 5.0.2アプリケーションを作成し、コンソールを実行します。

それから私は私がfooのバーテキストコンソールでとlog/development.logファイルの両方を取得

irb(main):001:0> Rails.logger.debug 'foo bar' 
foo bar 
=> true 

を行います。私は@thread_key以外Rails.loggerとカスタムロガーとのあまりの違いが表示されない

Rails.loggerこの

#<ActiveSupport::Logger:0x007f9545860150 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f9545860088 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x007f95430b7d10 @datetime_format=nil, @thread_key="activesupport_tagged_logging_tags:70139525840520">, @logdev=#<Logger::LogDevice:0x007f9545861820 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<File:/Users/aleksey/projects/test-logger/log/development.log>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f9545863080>>, @local_levels=#<Concurrent::Map:0x007f9545893de8 entries=0 default_proc=nil>> 

のように見えます。しかし、私はカスタムロガーを作成する場合、私は、テキストのみのログファイルに

irb(main):005:0* logger = ActiveSupport::Logger.new('log/development.log') 
=> #<ActiveSupport::Logger:0x007f9543411588 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f9543411510 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x007f9543411330 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007f95434114c0 @shift_size=1048576, @shift_age=0, @filename="log/development.log", @dev=#<File:log/development.log>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f9543411448>>, @local_levels=#<Concurrent::Map:0x007f9543411290 entries=0 default_proc=nil>> 
irb(main):006:0> logger.debug 'foo bar' 
=> true 

を取得します私はそれがActiveSupport::TaggedLoggingから来ていることがわかりますが、私はそれが問題と関係しているとは思わない)。

問題がどこにあるか知りませんか?私は何が欠けているのですか?

Rails 4.2.8でも同じことが起こります。
MongoDB(mongoid gem)上で実行されているRails 4.2.8アプリケーションがあります。Rails.logger.debug('foo bar')は、のみログファイルにを出力します。
私は、全体が何とかActiveRecordに関係していると思います。
そうですか?

ありがとうございます。

答えて

0

ActiveRecordに似ているようです。
this にログブロードキャストを追加するコードがあります。

関連する問題