LoginSignup
0
1

More than 1 year has passed since last update.

Railsのログにcookieの値を出力する

Last updated at Posted at 2019-12-17

Railsのログにcookieの値を出力する

config.log_tagsを使ってログ情報追加する。

rails newするとデフォルトでconfig/environments配下の環境別ファイルに記述されている設定値。

RailsGuideより

config.log_tags: 次のリストを引数に取ります(requestオブジェクトが応答するメソッド、requestオブジェクトを受け取るProc、またはto_sに応答できるオブジェクト)。これは、ログの行にデバッグ情報をタグ付けする場合に便利です。たとえばサブドメインやリクエストidを指定することができ、これらはマルチユーザーのproductionアプリケーションをデバッグするのに便利です。

requestオブジェクトを受け取るProcを指定できるので、以下の様にlambdaを指定する

config/environments/production.rb
Rails.configuration.log_tags = [
  :request_id,
+  lambda { |req| req.cookies["_hoge_session"] }
]
0
1
1

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
1