From d8ecebbd8a8d10259bf7c77a15b84d0cbee6629d Mon Sep 17 00:00:00 2001 From: Bill Dueber Date: Wed, 22 Jan 2025 12:17:29 -0500 Subject: [PATCH] Use semantic logger --- Gemfile | 6 +- Gemfile.lock | 258 +++++++++++++++++++----------------- config/application.rb | 70 +++++----- config/load_local_config.rb | 1 - 4 files changed, 173 insertions(+), 162 deletions(-) diff --git a/Gemfile b/Gemfile index 8642bcc..54a1e15 100644 --- a/Gemfile +++ b/Gemfile @@ -112,9 +112,9 @@ gem "traject", require: false # only for indexing # Semantic logging? gem "awesome_print" -gem "semantic_logger" - -gem "lograge", ">=0.11.1" +# gem "semantic_logger" +gem "rails_semantic_logger" +# gem "lograge", ">=0.11.1" # Contacts Email gem "mail_form", "~>1.7" diff --git a/Gemfile.lock b/Gemfile.lock index 6ef1024..a7e3a1c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,29 +52,30 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.8.1) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) arel (9.0.0) ast (2.4.2) - autoprefixer-rails (10.4.13.0) + autoprefixer-rails (10.4.19.0) execjs (~> 2) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.971.0) - aws-sdk-core (3.203.0) + aws-partitions (1.1041.0) + aws-sdk-core (3.216.0) aws-eventstream (~> 1, >= 1.3.0) - aws-partitions (~> 1, >= 1.651.0) + aws-partitions (~> 1, >= 1.992.0) aws-sigv4 (~> 1.9) jmespath (~> 1, >= 1.6.1) - aws-sdk-kms (1.89.0) - aws-sdk-core (~> 3, >= 3.203.0) + aws-sdk-kms (1.97.0) + aws-sdk-core (~> 3, >= 3.216.0) aws-sigv4 (~> 1.5) - aws-sdk-s3 (1.160.0) - aws-sdk-core (~> 3, >= 3.203.0) + aws-sdk-s3 (1.178.0) + aws-sdk-core (~> 3, >= 3.216.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) - aws-sigv4 (1.9.1) + aws-sigv4 (1.11.0) aws-eventstream (~> 1, >= 1.0.2) + base64 (0.2.0) bindex (0.8.1) blacklight (6.15.0) bootstrap-sass (~> 3.2) @@ -89,9 +90,9 @@ GEM bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) - canister (0.9.1) + canister (0.9.2) coderay (1.1.3) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -100,43 +101,43 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.2.2) - connection_pool (2.3.0) + concurrent-ruby (1.3.5) + connection_pool (2.5.0) content_disposition (1.0.0) crass (1.0.6) - date (3.3.3) + date (3.4.1) date_named_file (0.1.1) - debase (0.2.4.1) - debase-ruby_core_source (>= 0.10.2) - debase-ruby_core_source (3.2.0) + debase (0.2.8) + debase-ruby_core_source (>= 3.3.6) + debase-ruby_core_source (3.4.1) declarative (0.0.20) deep_merge (1.2.2) deprecation (1.1.0) activesupport - diff-lcs (1.5.0) - docile (1.4.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) + diff-lcs (1.5.1) + docile (1.4.1) + domain_name (0.6.20240107) dot-properties (0.1.4) bundler (>= 2.2.33) down (5.4.2) addressable (~> 2.8) - erubi (1.12.0) + erubi (1.13.1) ettin (1.3.0) deep_merge - execjs (2.8.1) + execjs (2.10.0) factory_bot (4.11.1) activesupport (>= 3.0.0) factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faraday (2.7.4) + faraday (2.8.1) + base64 faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) - ffi (1.15.5) - ffi-compiler (1.0.1) - ffi (>= 1.0.0) + ffi (1.17.1) + ffi-compiler (1.3.2) + ffi (>= 1.15.5) rake globalid (1.1.0) activesupport (>= 5.0) @@ -149,29 +150,30 @@ GEM hashie (5.0.0) html_truncator (0.4.2) nokogiri (~> 1.5) - http-2 (1.0.1) - http (5.1.1) + http-2 (1.0.2) + http (5.2.0) addressable (~> 2.8) + base64 (~> 0.1) http-cookie (~> 1.0) http-form_data (~> 2.2) - llhttp-ffi (~> 0.4.0) - http-cookie (1.0.5) + llhttp-ffi (~> 0.5.0) + http-cookie (1.0.8) domain_name (~> 0.5) http-form_data (2.3.0) httpclient (2.8.3) - httpx (1.3.1) + httpx (1.4.0) http-2 (>= 1.0.0) - i18n (1.12.0) + i18n (1.14.7) concurrent-ruby (~> 1.0) - jbuilder (2.11.5) + jbuilder (2.13.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) jmespath (1.6.2) - jquery-rails (4.5.1) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.6.3) + json (2.9.1) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -185,76 +187,72 @@ GEM kaminari-core (= 1.2.2) kaminari-core (1.2.2) language_server-protocol (3.17.0.3) - listen (3.8.0) + lint_roller (1.1.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - llhttp-ffi (0.4.0) + llhttp-ffi (0.5.0) ffi-compiler (~> 1.0) rake (~> 13.0) - lograge (0.12.0) - actionpack (>= 4) - activesupport (>= 4) - railties (>= 4) - request_store (~> 1.0) - loofah (2.19.1) + logger (1.6.5) + loofah (2.24.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop net-smtp - mail_form (1.10.0) + mail_form (1.10.1) actionmailer (>= 5.2) activemodel (>= 5.2) - marc (1.2.0) + marc (1.3.0) + nokogiri (~> 1.0) rexml - scrub_rb (>= 1.0.1, < 2) - unf marc-fastxmlwriter (1.1.0) marc (~> 1.0) - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.18.0) + marcel (1.0.4) + method_source (1.1.0) + mini_mime (1.1.5) + minitest (5.25.4) multi_json (1.15.0) mysql2 (0.4.10) nestive (0.6.0) rails (>= 3.0.0) - net-imap (0.3.4) + net-imap (0.4.18) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.5.0) net-protocol nio4r (2.5.2) - nokogiri (1.13.10-aarch64-linux) + nokogiri (1.15.7-aarch64-linux) racc (~> 1.4) - nokogiri (1.13.10-x86_64-linux) - racc (~> 1.4) - okcomputer (1.18.4) - parallel (1.22.1) - parser (3.2.1.1) + okcomputer (1.18.6) + parallel (1.26.3) + parser (3.3.7.0) ast (~> 2.4.1) - pg (1.4.6) - prometheus-client (4.1.0) + racc + pg (1.5.9) + prometheus-client (4.2.3) + base64 pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.10.1) byebug (~> 11.0) pry (>= 0.13, < 0.15) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (5.0.1) - puma (6.3.1) + pry-rails (0.3.11) + pry (>= 0.13.0) + public_suffix (5.1.1) + puma (6.5.0) nio4r (~> 2.0) - racc (1.6.2) - rack (2.2.6.4) - rack-test (2.1.0) + racc (1.8.1) + rack (2.2.10) + rack-test (2.2.0) rack (>= 1.3) rails (5.2.8.1) actioncable (= 5.2.8.1) @@ -269,11 +267,17 @@ GEM bundler (>= 1.3.0) railties (= 5.2.8.1) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + rails_semantic_logger (4.17.0) + rack + railties (>= 5.1) + semantic_logger (~> 4.16) railties (5.2.8.1) actionpack (= 5.2.8.1) activesupport (= 5.2.8.1) @@ -281,22 +285,21 @@ GEM rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.1.1) - rake (13.0.6) + rake (13.2.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) - redis (4.8.1) - regexp_parser (2.7.0) + redis-client (0.23.2) + connection_pool + regexp_parser (2.10.0) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) - request_store (1.5.1) - rack (>= 1.4) - rexml (3.2.5) - roda (3.83.0) + rexml (3.4.0) + roda (3.88.0) rack - rsolr (2.5.0) + rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) rspec-core (3.9.3) @@ -316,27 +319,28 @@ GEM rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) rspec-support (3.9.4) - rubocop (1.48.1) + rubocop (1.64.1) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.26.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.27.0) - parser (>= 3.2.1.0) - rubocop-performance (1.16.0) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - ruby-debug-ide (0.7.3) + rubocop-ast (1.37.0) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-debug-ide (0.7.4) rake (>= 0.8.1) - ruby-prof (1.6.1) + ruby-prof (1.6.3) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) - rubyzip (2.3.2) + rubyzip (2.4.1) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -350,21 +354,22 @@ GEM tilt (>= 1.1, < 3) sassc (2.4.0) ffi (~> 1.9) - scrub_rb (1.0.1) - selenium-webdriver (4.8.1) + selenium-webdriver (4.9.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - semantic_logger (4.12.0) + semantic_logger (4.16.1) concurrent-ruby (~> 1.0) shrine (3.6.0) content_disposition (~> 1.0) down (~> 5.1) - sidekiq (6.5.8) - connection_pool (>= 2.2.5, < 3) - rack (~> 2.0) - redis (>= 4.5.0, < 5) - simple_form (5.2.0) + sidekiq (7.3.8) + base64 + connection_pool (>= 2.3.0) + logger + rack (>= 2.2.4) + redis-client (>= 0.22.2) + simple_form (5.3.1) actionpack (>= 5.2) activemodel (>= 5.2) simple_solr_client (0.2.1) @@ -374,14 +379,15 @@ GEM docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) slop (4.10.1) solr_cloud-connection (0.6.0) faraday (~> 2.0) httpx (~> 1.0) rubyzip (~> 2.0) - sprockets (3.7.2) + sprockets (3.7.5) + base64 concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.4.2) @@ -389,16 +395,24 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.3.13) - standard (1.25.3) + standard (1.37.0) language_server-protocol (~> 3.17.0.2) - rubocop (~> 1.48.1) - rubocop-performance (~> 1.16.0) - thor (1.2.1) + lint_roller (~> 1.0) + rubocop (~> 1.64.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + thor (1.3.2) thread_safe (0.3.6) - tilt (2.1.0) - timeout (0.3.2) + tilt (2.6.0) + timeout (0.4.3) trailblazer-option (0.1.2) - traject (3.8.1) + traject (3.8.2) concurrent-ruby (>= 0.8.0) dot-properties (>= 0.1.1) hashie (>= 3.1, < 6) @@ -419,12 +433,9 @@ GEM tzinfo (1.2.11) thread_safe (~> 0.1) uber (0.1.0) - uglifier (4.2.0) + uglifier (4.2.1) execjs (>= 0.3.0, < 3) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.2) - unicode-display_width (2.4.2) + unicode-display_width (2.6.0) uppy-s3_multipart (1.2.1) aws-sdk-s3 (~> 1.0) content_disposition (~> 1.0) @@ -434,8 +445,9 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket (1.2.9) - websocket-driver (0.7.5) + websocket (1.2.11) + websocket-driver (0.7.7) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) yell (2.2.2) @@ -443,7 +455,6 @@ GEM PLATFORMS aarch64-linux - x86_64-linux DEPENDENCIES actionpack (>= 5.2.4.3) @@ -466,7 +477,6 @@ DEPENDENCIES jquery-rails kaminari (>= 1.2.1) listen - lograge (>= 0.11.1) loofah (>= 2.3.1) mail_form (~> 1.7) middle_english_dictionary! @@ -482,6 +492,7 @@ DEPENDENCIES puma (>= 4.3.5) rack (>= 2.1.4) rails (~> 5.0) + rails_semantic_logger rake (~> 13.0) rsolr (>= 1.0) rspec-rails (~> 3.6) @@ -489,7 +500,6 @@ DEPENDENCIES ruby-prof sass-rails (~> 5.0) selenium-webdriver - semantic_logger shrine (~> 3.6) sidekiq simple_form (~> 5.0) diff --git a/config/application.rb b/config/application.rb index d4aac71..ec6c259 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,18 +7,18 @@ # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -# JSON_FORMATTER = ->(log, logger) do -# h = log.to_h(logger.host) -# h[:application] = 'MED' -# if h[:named_tags] -# h[:ip] = h[:named_tags].delete(:ip) if h[:named_tags].has_key?(:ip) -# h.delete(:named_tags) if h[:named_tags].empty? -# end -# -# h[:payload] && h[:payload][:params] && h[:payload][:params].delete('utf8') -# -# h.to_json -# end +JSON_FORMATTER = ->(log, logger) do + h = log.to_h(logger.host) + h[:application] = 'MED' + if h[:named_tags] + h[:ip] = h[:named_tags].delete(:ip) if h[:named_tags].has_key?(:ip) + h.delete(:named_tags) if h[:named_tags].empty? + end + + ditch_payload_keys = %w(utf8 ) + h[:payload] && h[:payload][:params] && h[:payload][:params].delete('utf8') + h.to_json +end module Dromedary class Application < Rails::Application @@ -42,35 +42,37 @@ class Application < Rails::Application config.log_level = :info config.web_console.whiny_requests = false - config.lograge.enabled = true + # config.lograge.enabled = true # add time to lograge - config.lograge.custom_options = lambda do |event| - {time: event.time} - end - - config.lograge.custom_payload do |controller| - { - host: controller.request.host, - ip: controller.request.ip, - query: controller.request.query_parameters - } - end - - config.lograge.formatter = Lograge::Formatters::Json.new - config.active_job.queue_adapter = :sidekiq + # config.lograge.custom_options = lambda do |event| + # {time: event.time} + # end + + # config.lograge.custom_payload do |controller| + # { + # host: controller.request.host, + # ip: controller.request.ip, + # query: controller.request.query_parameters + # } + # end + # + # config.lograge.formatter = Lograge::Formatters::Json.new + config.active_job.queue_adapter = :sidekiq config.active_record.yaml_column_permitted_classes = [ActiveSupport::HashWithIndifferentAccess] - # config.log_tags = { - # ip: :remote_ip, - # } - # config.rails_semantic_logger.quiet_assets = true - # config.rails_semantic_logger.format = :json + config.log_tags = { + ip: :remote_ip, + } + + config.rails_semantic_logger.console_logger = false + config.rails_semantic_logger.quiet_assets = true + config.rails_semantic_logger.format = :json - # config.rails_semantic_logger.add_file_appender = false + config.rails_semantic_logger.add_file_appender = false # config.semantic_logger.add_appender(file_name: "log/#{Rails.env}.log", level: :info) - # config.semantic_logger.add_appender(file_name: "log/#{Rails.env}.json", formatter: JSON_FORMATTER, level: :info) + config.semantic_logger.add_appender(file_name: "log/#{Rails.env}.json", formatter: JSON_FORMATTER, level: :info) # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/config/load_local_config.rb b/config/load_local_config.rb index ecd6460..d1fb2ed 100644 --- a/config/load_local_config.rb +++ b/config/load_local_config.rb @@ -40,7 +40,6 @@ def hyp_to_bibid end def collection_creation_date - Rails.logger.warn "################# Fetching creation date ########################" collection = Dromedary::Services[:solr_current_collection] if collection Dromedary.compute_collection_creation_date collection.collection.name