Одна вещь, которую я сделал, чтобы сделать журналы немного тише, - это отфильтровать некоторые связанные с ActiveStorage параметры из журналов. Я добавил :encoded_key
, :signed_blob_id
и :variation_key
к отфильтрованным параметрам в config/initializers/filter_parameter_logging.rb
:
Rails.application.config.filter_parameters += [
:password,
# Filter ActiveStorage blob keys so that the logs aren't full of as much stuff.
:encoded_key,
:signed_blob_id,
:variation_key
]
До:
Started GET "/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZiMDVvUjNCblJIQm9RVWd6YWtGeFFWUlpPV0Z3U2tWSUwyRTBZemd3WVRCallUUTJZalJtWmpObE16Vm1aV1l5TVRFelltWmxPREptWlRsalpUbGhNalE0WmpWaE9UZ3hZVEk1WkdVek5XUmxNemt4Wm1VNE1HUUdPZ1pGVkRvUVpHbHpjRzl6YVhScGIyNUpJazFwYm14cGJtVTdJR1pwYkdWdVlXMWxQU0kzWDJaaGEyVnlYMk52ZG1WeUxtcHdaeUk3SUdacGJHVnVZVzFsS2oxVlZFWXRPQ2NuTjE5bVlXdGxjbDlqYjNabGNpNXFjR2NHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc5cGJXRm5aUzlxY0dWbkJqc0dWQT09IiwiZXhwIjoiMjAxOS0wMi0yNFQyMDoxNTo1MS45OTFaIiwicHVyIjoiYmxvYl9rZXkifX0=--c8b11cdaa201d28d585f62aaa7c8cf6af75e7cab/7_faker_cover.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%227_faker_cover.jpg%22%3B+filename%2A%3DUTF-8%27%277_faker_cover.jpg" for 127.0.0.1 at 2019-02-24 13:10:52 -0700
Processing by ActiveStorage::DiskController#show as JPEG
Parameters: {"content_type"=>"image/jpeg", "disposition"=>"inline; filename=\"7_faker_cover.jpg\"; filename*=UTF-8''7_faker_cover.jpg", "encoded_key"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZiMDVvUjNCblJIQm9RVWd6YWtGeFFWUlpPV0Z3U2tWSUwyRTBZemd3WVRCallUUTJZalJtWmpObE16Vm1aV1l5TVRFelltWmxPREptWlRsalpUbGhNalE0WmpWaE9UZ3hZVEk1WkdVek5XUmxNemt4Wm1VNE1HUUdPZ1pGVkRvUVpHbHpjRzl6YVhScGIyNUpJazFwYm14cGJtVTdJR1pwYkdWdVlXMWxQU0kzWDJaaGEyVnlYMk52ZG1WeUxtcHdaeUk3SUdacGJHVnVZVzFsS2oxVlZFWXRPQ2NuTjE5bVlXdGxjbDlqYjNabGNpNXFjR2NHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc5cGJXRm5aUzlxY0dWbkJqc0dWQT09IiwiZXhwIjoiMjAxOS0wMi0yNFQyMDoxNTo1MS45OTFaIiwicHVyIjoiYmxvYl9rZXkifX0=--c8b11cdaa201d28d585f62aaa7c8cf6af75e7cab", "filename"=>"7_faker_cover"}
Completed 200 OK in 2ms (ActiveRecord: 0.0ms)
После того, как:
Started GET "/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZiMDVvUjNCblJIQm9RVWd6YWtGeFFWUlpPV0Z3U2tWSUwyRTBZemd3WVRCallUUTJZalJtWmpObE16Vm1aV1l5TVRFelltWmxPREptWlRsalpUbGhNalE0WmpWaE9UZ3hZVEk1WkdVek5XUmxNemt4Wm1VNE1HUUdPZ1pGVkRvUVpHbHpjRzl6YVhScGIyNUpJazFwYm14cGJtVTdJR1pwYkdWdVlXMWxQU0kzWDJaaGEyVnlYMk52ZG1WeUxtcHdaeUk3SUdacGJHVnVZVzFsS2oxVlZFWXRPQ2NuTjE5bVlXdGxjbDlqYjNabGNpNXFjR2NHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc5cGJXRm5aUzlxY0dWbkJqc0dWQT09IiwiZXhwIjoiMjAxOS0wMi0yNFQyMDoxNjozNy43MTlaIiwicHVyIjoiYmxvYl9rZXkifX0=--223b806011854805e1e50ca952099bcdbc4d8bdd/7_faker_cover.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%227_faker_cover.jpg%22%3B+filename%2A%3DUTF-8%27%277_faker_cover.jpg" for 127.0.0.1 at 2019-02-24 13:11:37 -0700
Processing by ActiveStorage::DiskController#show as JPEG
Parameters: {"content_type"=>"image/jpeg", "disposition"=>"inline; filename=\"7_faker_cover.jpg\"; filename*=UTF-8''7_faker_cover.jpg", "encoded_key"=>"[FILTERED]", "filename"=>"7_faker_cover"}
Completed 200 OK in 1ms (ActiveRecord: 0.0ms)
Большая часть изменений находится в третьей строке, параметры намного короче. К сожалению, это почти все, что я мог понять
Мне любопытно, можно ли отключить журналы, помеченные как Дисковое хранилище (строки «Проверено, существует ли файл по ключу:» и «Сгенерированный URL для файла по ключу:»):
Started GET "/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBGQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6b1335aa96f07d0e8a19178e8d4c65d4a6b6ec60/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21WemFYcGxTU0lOTXpBd2VEVXdNRDRHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--aca35120fd4bdbafe23b34690fa45f96280194c4/7_faker_cover.jpg" for 127.0.0.1 at 2019-02-24 13:11:37 -0700
Processing by ActiveStorage::RepresentationsController#show as JPEG
Parameters: {"signed_blob_id"=>"[FILTERED]", "variation_key"=>"[FILTERED]", "filename"=>"7_faker_cover"}
ActiveStorage::Blob Load (1.1ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 15], ["LIMIT", 1]]
↳ /Users/connorshea/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Disk Storage (0.1ms) Checked if file exists at key: variants/oNhGpgDphAH3jAqATY9apJEH/a4c80a0ca46b4ff3e35fef2113bfe82fe9ce9a248f5a981a29de35de391fe80d (yes)
Disk Storage (276.0ms) Generated URL for file at key: variants/oNhGpgDphAH3jAqATY9apJEH/a4c80a0ca46b4ff3e35fef2113bfe82fe9ce9a248f5a981a29de35de391fe80d (http://localhost:3000/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZiMDVvUjNCblJIQm9RVWd6YWtGeFFWUlpPV0Z3U2tWSUwyRTBZemd3WVRCallUUTJZalJtWmpObE16Vm1aV1l5TVRFelltWmxPREptWlRsalpUbGhNalE0WmpWaE9UZ3hZVEk1WkdVek5XUmxNemt4Wm1VNE1HUUdPZ1pGVkRvUVpHbHpjRzl6YVhScGIyNUpJazFwYm14cGJtVTdJR1pwYkdWdVlXMWxQU0kzWDJaaGEyVnlYMk52ZG1WeUxtcHdaeUk3SUdacGJHVnVZVzFsS2oxVlZFWXRPQ2NuTjE5bVlXdGxjbDlqYjNabGNpNXFjR2NHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc5cGJXRm5aUzlxY0dWbkJqc0dWQT09IiwiZXhwIjoiMjAxOS0wMi0yNFQyMDoxNjozNy43MTlaIiwicHVyIjoiYmxvYl9rZXkifX0=--223b806011854805e1e50ca952099bcdbc4d8bdd/7_faker_cover.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%227_faker_cover.jpg%22%3B+filename%2A%3DUTF-8%27%277_faker_cover.jpg)
Redirected to http://localhost:3000/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZiMDVvUjNCblJIQm9RVWd6YWtGeFFWUlpPV0Z3U2tWSUwyRTBZemd3WVRCallUUTJZalJtWmpObE16Vm1aV1l5TVRFelltWmxPREptWlRsalpUbGhNalE0WmpWaE9UZ3hZVEk1WkdVek5XUmxNemt4Wm1VNE1HUUdPZ1pGVkRvUVpHbHpjRzl6YVhScGIyNUpJazFwYm14cGJtVTdJR1pwYkdWdVlXMWxQU0kzWDJaaGEyVnlYMk52ZG1WeUxtcHdaeUk3SUdacGJHVnVZVzFsS2oxVlZFWXRPQ2NuTjE5bVlXdGxjbDlqYjNabGNpNXFjR2NHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc5cGJXRm5aUzlxY0dWbkJqc0dWQT09IiwiZXhwIjoiMjAxOS0wMi0yNFQyMDoxNjozNy43MTlaIiwicHVyIjoiYmxvYl9rZXkifX0=--223b806011854805e1e50ca952099bcdbc4d8bdd/7_faker_cover.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%227_faker_cover.jpg%22%3B+filename%2A%3DUTF-8%27%277_faker_cover.jpg
Completed 302 Found in 300ms (ActiveRecord: 16.7ms)
Я предполагал, что они используют функциональность Rails TaggedLogging , но не похоже, что они есть (см. Исходный код ). Если не считать исправлений в логгере ActiveStorage (что кажется довольно плохой идеей), я не уверен в хорошем способе улучшить эту ситуацию.