LoginSignup
63
56

More than 5 years have passed since last update.

[Rails] 任意のファイルにアプリケーションログを吐く

Last updated at Posted at 2014-08-13

基本はlog/production.loglog/development.logに吐かれるログだが、特定機能のログは別ファイルに残したい場合など。

configへ設定

今回はlog/foo.logに吐かれるようにしてみます。

environments/production.rb
config.another_logger = Logger.new(Rails.root.join('log/foo.log'))

使う

fuga_controller.rb
Rails.application.config.another_logger.info('bar')

これだけです。

並行して、通常通りproduction.logに吐かせたいものは

fuga_controller.rb
Rails.logger.info('buzz')

にて。

63
56
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
63
56