LoginSignup
0
0

More than 5 years have passed since last update.

HerokuでRails動かすときのカスタムLogFormatterでハマった話

Last updated at Posted at 2018-11-09

※ はてなブログから技術ネタを移動しました
※ 初稿: 2018/03/31

TL;DR

結論から言うと、Rails 5を使うときはrails_12factor gemは使わないほうが良さそう。

くわしく

アプリケーションログベースでの監視をしたい/アラートを上げたいので、loggerの上げるログのseverity(ログレベル)の情報はかなり重要。この辺の情報はloggerのformatterにActiveSupport::Logger::SimpleFormatterを使っちゃうと消されてしまうが、::Logger::Formatterを使えば指定すれば消されずに出力される。

config/environments/production.rb
config.log_formatter = ::Logger::Formatter.new

しかし、herokuにデプロイしているアプリで上記のFormatterが動いてくれずに非常に時間を消費してしまった。いくらformatterを変えても、強制的にActiveSupport::Logger::SimpleFormatterが使われてしまう。そういえば、rails_12factor gemってherokuでログを標準出力に吐き出す設定を良しなにやってくれるgemだったっけ?考えられるとしたらこれしか無いな...

よく読んでみると

If you are starting a new application with Rails 5, you do not need this gem.

Rails 5ではもうこのgem要らないらしい。マジか。

Gemfileからgem "rails_12factor"の行を消したらちゃんと動いた。

0
0
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
0
0