From 817f74729d61c0457b9a1e7a656aa9c19358e865 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 13 Dec 2019 13:28:42 +0000 Subject: [PATCH] use logstash format for all logging --- app/controllers/client_prefixes_controller.rb | 4 ++-- app/controllers/clients_controller.rb | 12 +++++----- app/controllers/concerns/facetable.rb | 2 +- app/controllers/dois_controller.rb | 22 +++++++++---------- app/controllers/media_controller.rb | 12 +++++----- app/controllers/metadata_controller.rb | 8 +++---- app/controllers/prefixes_controller.rb | 4 ++-- .../provider_prefixes_controller.rb | 4 ++-- app/controllers/providers_controller.rb | 12 +++++----- app/controllers/repositories_controller.rb | 12 +++++----- .../repository_prefixes_controller.rb | 4 ++-- app/controllers/sessions_controller.rb | 2 +- .../activity_convert_affiliation_by_id_job.rb | 2 +- app/jobs/activity_import_by_id_job.rb | 2 +- app/jobs/affiliation_job.rb | 2 +- app/jobs/crossref_doi_by_id_job.rb | 4 ++-- app/jobs/delete_job.rb | 2 +- app/jobs/doi_convert_affiliation_by_id_job.rb | 2 +- app/jobs/doi_convert_container_by_id_job.rb | 2 +- app/jobs/doi_import_by_id_job.rb | 2 +- app/jobs/event_registrant_update_by_id_job.rb | 6 ++--- app/jobs/handle_job.rb | 2 +- app/jobs/index_job.rb | 2 +- app/jobs/orcid_auto_update_by_id_job.rb | 4 ++-- app/jobs/transfer_job.rb | 2 +- app/jobs/update_state_job.rb | 2 +- app/jobs/url_job.rb | 2 +- app/models/activity.rb | 4 ++-- app/models/concerns/authenticable.rb | 12 +++++----- app/models/concerns/crosscitable.rb | 4 ++-- app/models/concerns/helpable.rb | 10 ++++----- app/models/concerns/indexable.rb | 2 +- app/models/concerns/userable.rb | 2 +- app/models/doi.rb | 20 ++++++++--------- app/models/event.rb | 10 ++++----- app/models/handle.rb | 2 +- app/models/user.rb | 2 -- 37 files changed, 101 insertions(+), 103 deletions(-) diff --git a/app/controllers/client_prefixes_controller.rb b/app/controllers/client_prefixes_controller.rb index 9b6681479..36b899c16 100644 --- a/app/controllers/client_prefixes_controller.rb +++ b/app/controllers/client_prefixes_controller.rb @@ -79,7 +79,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @client_prefix = ClientPrefix.new(safe_params) authorize! :create, @client_prefix @@ -90,7 +90,7 @@ def create render json: ClientPrefixSerializer.new(@client_prefix, options).serialized_json, status: :created else - logger.warn @client_prefix.errors.inspect + logger.error @client_prefix.errors.inspect render json: serialize_errors(@client_prefix.errors), status: :unprocessable_entity end end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index ac8dbb441..31f08c7eb 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -105,7 +105,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @client = Client.new(safe_params) authorize! :create, @client @@ -116,13 +116,13 @@ def create render json: ClientSerializer.new(@client, options).serialized_json, status: :created else - logger.warn @client.errors.inspect + logger.error @client.errors.inspect render json: serialize_errors(@client.errors), status: :unprocessable_entity end end def update - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if @client.update_attributes(safe_params) options = {} options[:meta] = { dois: doi_count(client_id: params[:id]) } @@ -131,7 +131,7 @@ def update render json: ClientSerializer.new(@client, options).serialized_json, status: :ok else - logger.warn @client.errors.inspect + logger.error @client.errors.inspect render json: serialize_errors(@client.errors), status: :unprocessable_entity end end @@ -139,7 +139,7 @@ def update # don't delete, but set deleted_at timestamp # a client with dois or prefixes can't be deleted def destroy - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if @client.dois.present? message = "Can't delete client that has DOIs." status = 400 @@ -149,7 +149,7 @@ def destroy @client.send_delete_email unless Rails.env.test? head :no_content else - logger.warn @client.errors.inspect + logger.error @client.errors.inspect render json: serialize_errors(@client.errors), status: :unprocessable_entity end end diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index cadd1ffc6..52b986f0b 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -342,7 +342,7 @@ def prefixes_totals(arr) end def clients_totals(arr) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) clients = Client.all.pluck(:symbol, :name).to_h diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 443066933..b2fe2a397 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -13,7 +13,7 @@ class DoisController < ApplicationController def index authorize! :read, Doi - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) sort = case params[:sort] when "name" then { "doi" => { order: 'asc' }} @@ -260,7 +260,7 @@ def show end def validate - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) # logger.info safe_params.inspect @doi = Doi.new(safe_params.merge(only_validate: true)) @@ -283,7 +283,7 @@ def validate end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) # logger.info safe_params.inspect fail CanCan::AuthorizationNotPerformed unless current_user.present? @@ -306,13 +306,13 @@ def create render json: DoiSerializer.new(@doi, options).serialized_json, status: :created, location: @doi else - logger.warn @doi.errors.inspect + logger.error @doi.errors.inspect render json: serialize_errors(@doi.errors), include: @include, status: :unprocessable_entity end end def update - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) # logger.info safe_params.inspect @doi = Doi.where(doi: params[:id]).first @@ -354,13 +354,13 @@ def update render json: DoiSerializer.new(@doi, options).serialized_json, status: exists ? :ok : :created else - logger.warn @doi.errors.messages + logger.error @doi.errors.messages render json: serialize_errors(@doi.errors.messages), include: @include, status: :unprocessable_entity end end def undo - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @doi = Doi.where(doi: safe_params[:doi]).first fail ActiveRecord::RecordNotFound unless @doi.present? @@ -379,13 +379,13 @@ def undo render json: DoiSerializer.new(@doi, options).serialized_json, status: :ok else - logger.warn @doi.errors.messages + logger.error @doi.errors.messages render json: serialize_errors(@doi.errors.messages), include: @include, status: :unprocessable_entity end end def destroy - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @doi = Doi.where(doi: params[:id]).first fail ActiveRecord::RecordNotFound unless @doi.present? @@ -395,7 +395,7 @@ def destroy if @doi.destroy head :no_content else - logger.warn @doi.errors.inspect + logger.error @doi.errors.inspect render json: serialize_errors(@doi.errors), status: :unprocessable_entity end else @@ -485,7 +485,7 @@ def set_include private def safe_params - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) fail JSON::ParserError, "You need to provide a payload following the JSONAPI spec" unless params[:data].present? diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 5db302837..29b15cbd9 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -49,7 +49,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) authorize! :update, @doi @media = Media.new(safe_params.merge(doi: @doi)) @@ -61,13 +61,13 @@ def create render json: MediaSerializer.new(@media, options).serialized_json, status: :created else - logger.warn @media.errors.inspect + logger.error @media.errors.inspect render json: serialize_errors(@media.errors), status: :unprocessable_entity end end def update - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) authorize! :update, @doi if @media.update_attributes(safe_params.merge(doi: @doi)) @@ -77,19 +77,19 @@ def update render json: MediaSerializer.new(@media, options).serialized_json, status: :ok else - logger.warn @media.errors.inspect + logger.error @media.errors.inspect render json: serialize_errors(@media.errors), status: :unprocessable_entity end end def destroy - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) authorize! :update, @doi if @media.destroy head :no_content else - logger.warn @media.errors.inspect + logger.error @media.errors.inspect render json: serialize_errors(@media.errors), status: :unprocessable_entity end end diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb index 2ab6a25ad..dc75c306e 100644 --- a/app/controllers/metadata_controller.rb +++ b/app/controllers/metadata_controller.rb @@ -52,7 +52,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) authorize! :update, @doi # convert back to plain xml @@ -66,20 +66,20 @@ def create render json: MetadataSerializer.new(@metadata, options).serialized_json, status: :created else - logger.warn @metadata.errors.inspect + logger.error @metadata.errors.inspect render json: serialize_errors(@metadata.errors), status: :unprocessable_entity end end def destroy - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) authorize! :update, @doi if @doi.draft? if @metadata.destroy head :no_content else - logger.warn @metadata.errors.inspect + logger.error @metadata.errors.inspect render json: serialize_errors(@metadata.errors), status: :unprocessable_entity end else diff --git a/app/controllers/prefixes_controller.rb b/app/controllers/prefixes_controller.rb index ac668df83..6a9e107ad 100644 --- a/app/controllers/prefixes_controller.rb +++ b/app/controllers/prefixes_controller.rb @@ -114,7 +114,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @prefix = Prefix.new(safe_params) authorize! :create, @prefix @@ -125,7 +125,7 @@ def create render json: PrefixSerializer.new(@prefix, options).serialized_json, status: :created, location: @prefix else - logger.warn @prefix.errors.inspect + logger.error @prefix.errors.inspect render json: serialize_errors(@prefix.errors), status: :unprocessable_entity end end diff --git a/app/controllers/provider_prefixes_controller.rb b/app/controllers/provider_prefixes_controller.rb index d04c282db..7bdcd6a18 100644 --- a/app/controllers/provider_prefixes_controller.rb +++ b/app/controllers/provider_prefixes_controller.rb @@ -113,7 +113,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @provider_prefix = ProviderPrefix.new(safe_params) authorize! :create, @provider_prefix @@ -124,7 +124,7 @@ def create render json: ProviderPrefixSerializer.new(@provider_prefix, options).serialized_json, status: :created else - logger.warn @provider_prefix.errors.inspect + logger.error @provider_prefix.errors.inspect render json: serialize_errors(@provider_prefix.errors), status: :unprocessable_entity end end diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 4b01243b2..781b9d7e4 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -181,7 +181,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) # generate random symbol if not symbol is provided @provider = Provider.new(safe_params.reverse_merge(symbol: generate_random_provider_symbol)) @@ -213,13 +213,13 @@ def create render json: ProviderSerializer.new(@provider, options).serialized_json, status: :ok else - logger.warn @provider.errors.inspect + logger.error @provider.errors.inspect render json: serialize_errors(@provider.errors), status: :unprocessable_entity end end def update - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) # logger.debug safe_params.inspect if @provider.update_attributes(safe_params) if params[:id] == "admin" @@ -247,7 +247,7 @@ def update render json: ProviderSerializer.new(@provider, options).serialized_json, status: :ok else - logger.warn @provider.errors.inspect + logger.error @provider.errors.inspect render json: serialize_errors(@provider.errors), status: :unprocessable_entity end end @@ -255,7 +255,7 @@ def update # don't delete, but set deleted_at timestamp # a provider with active clients or with prefixes can't be deleted def destroy - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if active_client_count(provider_id: @provider.symbol) > 0 message = "Can't delete provider that has active clients." status = 400 @@ -265,7 +265,7 @@ def destroy @provider.send_delete_email unless Rails.env.test? head :no_content else - logger.warn @provider.errors.inspect + logger.error @provider.errors.inspect render json: serialize_errors(@provider.errors), status: :unprocessable_entity end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 619ef28b4..7abf332cf 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -132,7 +132,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @client = Client.new(safe_params) authorize! :create, @client @@ -143,13 +143,13 @@ def create render json: RepositorySerializer.new(@client, options).serialized_json, status: :created else - logger.warn @client.errors.inspect + logger.error @client.errors.inspect render json: serialize_errors(@client.errors), status: :unprocessable_entity end end def update - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if @client.update_attributes(safe_params) options = {} options[:meta] = { dois: doi_count(client_id: params[:id]) } @@ -158,7 +158,7 @@ def update render json: RepositorySerializer.new(@client, options).serialized_json, status: :ok else - logger.warn @client.errors.inspect + logger.error @client.errors.inspect render json: serialize_errors(@client.errors), status: :unprocessable_entity end end @@ -166,7 +166,7 @@ def update # don't delete, but set deleted_at timestamp # a repository with dois or prefixes can't be deleted def destroy - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if @client.dois.present? message = "Can't delete repository that has DOIs." status = 400 @@ -176,7 +176,7 @@ def destroy @client.send_delete_email unless Rails.env.test? head :no_content else - logger.warn @client.errors.inspect + logger.error @client.errors.inspect render json: serialize_errors(@client.errors), status: :unprocessable_entity end end diff --git a/app/controllers/repository_prefixes_controller.rb b/app/controllers/repository_prefixes_controller.rb index f0704a8e2..5e1321aef 100644 --- a/app/controllers/repository_prefixes_controller.rb +++ b/app/controllers/repository_prefixes_controller.rb @@ -79,7 +79,7 @@ def show end def create - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) @client_prefix = ClientPrefix.new(safe_params) authorize! :create, @client_prefix @@ -90,7 +90,7 @@ def create render json: RepositoryPrefixSerializer.new(@client_prefix, options).serialized_json, status: :created else - logger.warn @client_prefix.errors.inspect + logger.error @client_prefix.errors.inspect render json: serialize_errors(@client_prefix.errors), status: :unprocessable_entity end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 30ecd0116..81def2a78 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -45,7 +45,7 @@ def reset private def error_response(message) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) status = 400 logger.info message render json: { errors: [{ status: status.to_s, title: message }] }.to_json, status: status diff --git a/app/jobs/activity_convert_affiliation_by_id_job.rb b/app/jobs/activity_convert_affiliation_by_id_job.rb index 0431cd7ba..91779dbea 100644 --- a/app/jobs/activity_convert_affiliation_by_id_job.rb +++ b/app/jobs/activity_convert_affiliation_by_id_job.rb @@ -2,7 +2,7 @@ class ActivityConvertAffiliationByIdJob < ActiveJob::Base queue_as :lupo_background rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end diff --git a/app/jobs/activity_import_by_id_job.rb b/app/jobs/activity_import_by_id_job.rb index 6eb33882a..b1d3644d5 100644 --- a/app/jobs/activity_import_by_id_job.rb +++ b/app/jobs/activity_import_by_id_job.rb @@ -2,7 +2,7 @@ class ActivityImportByIdJob < ActiveJob::Base queue_as :lupo_background rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end diff --git a/app/jobs/affiliation_job.rb b/app/jobs/affiliation_job.rb index 5a4efe802..f807d842d 100644 --- a/app/jobs/affiliation_job.rb +++ b/app/jobs/affiliation_job.rb @@ -2,7 +2,7 @@ class AffiliationJob < ActiveJob::Base queue_as :lupo_background def perform(doi_id) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first if doi.present? diff --git a/app/jobs/crossref_doi_by_id_job.rb b/app/jobs/crossref_doi_by_id_job.rb index c22c9d39f..276ef1d23 100644 --- a/app/jobs/crossref_doi_by_id_job.rb +++ b/app/jobs/crossref_doi_by_id_job.rb @@ -7,12 +7,12 @@ class CrossrefDoiByIdJob < ActiveJob::Base # discard_on ActiveJob::DeserializationError rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end def perform(id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = doi_from_url(id) return {} unless doi.present? diff --git a/app/jobs/delete_job.rb b/app/jobs/delete_job.rb index 4c690eaa0..6efa73f48 100644 --- a/app/jobs/delete_job.rb +++ b/app/jobs/delete_job.rb @@ -2,7 +2,7 @@ class DeleteJob < ActiveJob::Base queue_as :lupo_background def perform(doi_id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first if doi.present? diff --git a/app/jobs/doi_convert_affiliation_by_id_job.rb b/app/jobs/doi_convert_affiliation_by_id_job.rb index 5a1dff2dd..9cde0d439 100644 --- a/app/jobs/doi_convert_affiliation_by_id_job.rb +++ b/app/jobs/doi_convert_affiliation_by_id_job.rb @@ -2,7 +2,7 @@ class DoiConvertAffiliationByIdJob < ActiveJob::Base queue_as :lupo_background rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end diff --git a/app/jobs/doi_convert_container_by_id_job.rb b/app/jobs/doi_convert_container_by_id_job.rb index fdef9c408..db9acc6f4 100644 --- a/app/jobs/doi_convert_container_by_id_job.rb +++ b/app/jobs/doi_convert_container_by_id_job.rb @@ -2,7 +2,7 @@ class DoiConvertContainerByIdJob < ActiveJob::Base queue_as :lupo_background rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end diff --git a/app/jobs/doi_import_by_id_job.rb b/app/jobs/doi_import_by_id_job.rb index 98affb658..e17a08f36 100644 --- a/app/jobs/doi_import_by_id_job.rb +++ b/app/jobs/doi_import_by_id_job.rb @@ -2,7 +2,7 @@ class DoiImportByIdJob < ActiveJob::Base queue_as :lupo_background rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end diff --git a/app/jobs/event_registrant_update_by_id_job.rb b/app/jobs/event_registrant_update_by_id_job.rb index 88ed558f5..fbdf208c2 100644 --- a/app/jobs/event_registrant_update_by_id_job.rb +++ b/app/jobs/event_registrant_update_by_id_job.rb @@ -3,12 +3,12 @@ class EventRegistrantUpdateByIdJob < ActiveJob::Base rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end def perform(id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) item = Event.where(uuid: id).first return false unless item.present? @@ -45,7 +45,7 @@ def perform(id, options={}) end def get_crossref_member_id(id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = doi_from_url(id) # return "crossref.citations" unless doi.present? diff --git a/app/jobs/handle_job.rb b/app/jobs/handle_job.rb index 3177b1234..b1cf96204 100644 --- a/app/jobs/handle_job.rb +++ b/app/jobs/handle_job.rb @@ -7,7 +7,7 @@ class HandleJob < ActiveJob::Base # discard_on ActiveJob::DeserializationError def perform(doi_id) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first if doi.present? diff --git a/app/jobs/index_job.rb b/app/jobs/index_job.rb index 5dae405a6..33c1191a7 100644 --- a/app/jobs/index_job.rb +++ b/app/jobs/index_job.rb @@ -2,7 +2,7 @@ class IndexJob < ActiveJob::Base queue_as :lupo rescue_from ActiveJob::DeserializationError, Elasticsearch::Transport::Transport::Errors::BadRequest do |error| - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error error.message end diff --git a/app/jobs/orcid_auto_update_by_id_job.rb b/app/jobs/orcid_auto_update_by_id_job.rb index 9a9fb39f8..ec4dadc76 100644 --- a/app/jobs/orcid_auto_update_by_id_job.rb +++ b/app/jobs/orcid_auto_update_by_id_job.rb @@ -7,7 +7,7 @@ class OrcidAutoUpdateByIdJob < ActiveJob::Base # discard_on ActiveJob::DeserializationError def perform(id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) orcid = orcid_from_url(id) return {} unless orcid.present? @@ -48,7 +48,7 @@ def perform(id, options={}) if [200, 201].include?(response.status) logger.info "ORCID #{orcid} added." else - logger.warn "[Error for ORCID #{orcid}]: " + response.body["errors"].inspect + logger.info "[Error for ORCID #{orcid}]: " + response.body["errors"].inspect end end diff --git a/app/jobs/transfer_job.rb b/app/jobs/transfer_job.rb index 3c4790157..fd67ccbc9 100644 --- a/app/jobs/transfer_job.rb +++ b/app/jobs/transfer_job.rb @@ -7,7 +7,7 @@ class TransferJob < ActiveJob::Base # discard_on ActiveJob::DeserializationError def perform(doi_id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first if doi.present? && options[:target_id].present? diff --git a/app/jobs/update_state_job.rb b/app/jobs/update_state_job.rb index 59e65e095..f7fbb29d7 100644 --- a/app/jobs/update_state_job.rb +++ b/app/jobs/update_state_job.rb @@ -2,7 +2,7 @@ class UpdateStateJob < ActiveJob::Base queue_as :lupo_background def perform(doi_id, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first if doi.blank? diff --git a/app/jobs/url_job.rb b/app/jobs/url_job.rb index b7ba4163d..70a116ccf 100644 --- a/app/jobs/url_job.rb +++ b/app/jobs/url_job.rb @@ -7,7 +7,7 @@ class UrlJob < ActiveJob::Base # discard_on ActiveJob::DeserializationError def perform(doi_id) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first if doi.present? diff --git a/app/models/activity.rb b/app/models/activity.rb index c37dfabe2..7aec133de 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -211,7 +211,7 @@ def self.import_by_id(options={}) errors = 0 count = 0 - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) Activity.where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |activities| response = Activity.__elasticsearch__.client.bulk \ @@ -269,7 +269,7 @@ def self.convert_affiliation_by_id(options={}) id = options[:id].to_i count = 0 - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) Activity.where(id: id..(id + 499)).find_each do |activity| should_update = false diff --git a/app/models/concerns/authenticable.rb b/app/models/concerns/authenticable.rb index 9b9b157e3..771032e12 100644 --- a/app/models/concerns/authenticable.rb +++ b/app/models/concerns/authenticable.rb @@ -13,7 +13,7 @@ def encode_token(payload) private_key = OpenSSL::PKey::RSA.new(ENV['JWT_PRIVATE_KEY'].to_s.gsub('\n', "\n")) JWT.encode(payload, private_key, 'RS256') rescue OpenSSL::PKey::RSAError => e - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error e.inspect + " for " + payload.inspect nil @@ -27,7 +27,7 @@ def encode_alb_token(payload) private_key = OpenSSL::PKey.read(File.read(Rails.root.join("spec", "fixtures", "certs", "ec256-private.pem").to_s)) JWT.encode(payload, private_key, 'ES256') rescue OpenSSL::PKey::ECError => e - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error e.inspect + " for " + payload.inspect nil @@ -35,7 +35,7 @@ def encode_alb_token(payload) # decode JWT token using SHA-256 hash algorithm def decode_token(token) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) public_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'].to_s.gsub('\n', "\n")) payload = (JWT.decode token, public_key, true, { :algorithm => 'RS256' }).first @@ -58,7 +58,7 @@ def decode_token(token) # decode JWT token from AWS ALB using SHA-256 hash algorithm def decode_alb_token(token) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if Rails.env.test? public_key = OpenSSL::PKey.read(File.read(Rails.root.join("spec", "fixtures", "certs", "ec256-public.pem").to_s)) @@ -169,7 +169,7 @@ def encode_token(payload) private_key = OpenSSL::PKey::RSA.new(ENV['JWT_PRIVATE_KEY'].to_s.gsub('\n', "\n")) JWT.encode(payload, private_key, 'RS256') rescue OpenSSL::PKey::RSAError => e - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error e.inspect + " for " + payload.inspect nil @@ -182,7 +182,7 @@ def encode_alb_token(payload) private_key = OpenSSL::PKey.read(File.read(Rails.root.join("spec", "fixtures", "certs", "ec256-private.pem").to_s)) JWT.encode(payload, private_key, 'ES256') rescue OpenSSL::PKey::ECError => e - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error e.inspect + " for " + payload.inspect nil diff --git a/app/models/concerns/crosscitable.rb b/app/models/concerns/crosscitable.rb index 7557e5c10..a03ea7029 100644 --- a/app/models/concerns/crosscitable.rb +++ b/app/models/concerns/crosscitable.rb @@ -51,7 +51,7 @@ def parse_xml(input, options={}) rescue NoMethodError, ArgumentError => exception Raven.capture_exception(exception) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error "Error " + exception.message + " for doi " + @doi + "." logger.error exception @@ -118,7 +118,7 @@ def clean_xml(string) doc = Nokogiri::XML(string) { |config| config.strict.noblanks } doc.to_xml rescue ArgumentError, Encoding::CompatibilityError => exception - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error "Error " + exception.message + "." logger.error exception diff --git a/app/models/concerns/helpable.rb b/app/models/concerns/helpable.rb index 934360a7d..89358d1a3 100644 --- a/app/models/concerns/helpable.rb +++ b/app/models/concerns/helpable.rb @@ -13,7 +13,7 @@ module Helpable include Bolognese::DoiUtils def register_url - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) unless url.present? logger.error "[Handle] Error updating DOI " + doi + ": url missing." @@ -76,7 +76,7 @@ def get_url if response.status == 200 response else - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error "[Handle] Error fetching URL for DOI " + doi + ": " + response.body.inspect unless Rails.env.test? response end @@ -143,7 +143,7 @@ def get_dois(options={}) else text = "Error " + response.body["errors"].inspect - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error "[Handle] " + text User.send_notification_to_slack(text, title: "Error #{response.status.to_s}", level: "danger") unless Rails.env.test? end @@ -167,7 +167,7 @@ def get_doi(options={}) else text = "Error " + response.body["errors"].inspect - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error "[Handle] " + text User.send_notification_to_slack(text, title: "Error #{response.status.to_s}", level: "danger") unless Rails.env.test? response @@ -186,7 +186,7 @@ def delete_doi(options={}) else text = "Error " + response.body["errors"].inspect - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.error "[Handle] " + text User.send_notification_to_slack(text, title: "Error #{response.status.to_s}", level: "danger") unless Rails.env.test? response diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 366f3a131..56d20e58f 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -154,7 +154,7 @@ def query(query, options={}) search_after = options.dig(:page, :cursor).presence || [1, "1"] if self.name == "Doi" - sort = [{ created: "asc", doi: "asc" }] + sort = [{ created: "asc", uid: "asc" }] elsif self.name == "Event" sort = [{ created_at: "asc", uuid: "asc" }] elsif self.name == "Activity" diff --git a/app/models/concerns/userable.rb b/app/models/concerns/userable.rb index 94e5cddf9..9b3b3c0c6 100644 --- a/app/models/concerns/userable.rb +++ b/app/models/concerns/userable.rb @@ -3,7 +3,7 @@ module Userable included do def remove_users(id: nil, jwt: nil) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) result = Maremma.get user_url logger.info result.inspect diff --git a/app/models/doi.rb b/app/models/doi.rb index b258b741a..af5052579 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -532,7 +532,7 @@ def self.find_by_id(ids, options={}) end def self.import_one(doi_id: nil) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) doi = Doi.where(doi: doi_id).first unless doi.present? @@ -588,7 +588,7 @@ def self.import_by_id(options={}) errors = 0 count = 0 - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) Doi.where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |dois| response = Doi.__elasticsearch__.client.bulk \ @@ -679,7 +679,7 @@ def self.convert_affiliation_by_id(options={}) id = options[:id].to_i count = 0 - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) Doi.where(id: id..(id + 499)).find_each do |doi| should_update = false @@ -785,7 +785,7 @@ def self.convert_container_by_id(options={}) id = options[:id].to_i count = 0 - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) Doi.where(id: id..(id + 499)).find_each do |doi| should_update = false @@ -1044,7 +1044,7 @@ def check_container # to be used after DOIs were transferred to another DOI RA def self.delete_dois_by_prefix(prefix, options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if prefix.blank? Logger.error "[Error] No prefix provided." @@ -1080,7 +1080,7 @@ def self.delete_dois_by_prefix(prefix, options={}) # register DOIs in the handle system that have not been registered yet # provider europ registers their DOIs in the handle system themselves and are ignored def self.set_handle - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:europ -agency:Crossref", page: { size: 1, cursor: [] }) logger.info "#{response.results.total} DOIs found that are not registered in the Handle system." @@ -1104,7 +1104,7 @@ def self.set_handle end def self.set_url - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) response = Doi.query("-url:* (+provider_id:ethz OR -aasm_status:draft)", page: { size: 1, cursor: [] }) logger.info "#{response.results.total} DOIs with no URL found in the database." @@ -1128,7 +1128,7 @@ def self.set_url end def self.set_minted - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) response = Doi.query("provider_id:ethz AND +aasm_state:draft +url:*", page: { size: 1, cursor: [] }) logger.info "#{response.results.total} draft DOIs from provider ETHZ found in the database." @@ -1152,7 +1152,7 @@ def self.set_minted end def self.transfer(options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) if options[:client_id].blank? Logger.error "[Transfer] No client provided." @@ -1202,7 +1202,7 @@ def set_defaults end def self.migrate_landing_page(options={}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.info "Starting migration" # Handle camel casing first. diff --git a/app/models/event.rb b/app/models/event.rb index 70f23efa8..92948fd07 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -306,7 +306,7 @@ def self.import_by_id(options = {}) errors = 0 count = 0 - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) Event.where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |events| response = Event.__elasticsearch__.client.bulk \ @@ -342,7 +342,7 @@ def self.import_by_id(options = {}) end def self.update_crossref(options = {}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) size = (options[:size] || 1000).to_i cursor = (options[:cursor] || []) @@ -400,7 +400,7 @@ def self.update_datacite_medra(options = {}) end def self.update_datacite_ra(options = {}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) size = (options[:size] || 1000).to_i cursor = (options[:cursor] || []) @@ -430,7 +430,7 @@ def self.update_datacite_ra(options = {}) end def self.update_registrant(options = {}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) size = (options[:size] || 1000).to_i cursor = (options[:cursor] || []) @@ -461,7 +461,7 @@ def self.update_registrant(options = {}) end def self.update_datacite_orcid_auto_update(options = {}) - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) size = (options[:size] || 1000).to_i cursor = (options[:cursor] || []).to_i diff --git a/app/models/handle.rb b/app/models/handle.rb index fdbf2073b..636cfc6aa 100644 --- a/app/models/handle.rb +++ b/app/models/handle.rb @@ -48,7 +48,7 @@ def self.get_query_url(options={}) def self.parse_data(result, options={}) return nil if result.blank? || result['errors'] - logger = Logger.new(STDOUT) + logger = LogStashLogger.new(type: :stdout) logger.debug result if options[:id] diff --git a/app/models/user.rb b/app/models/user.rb index 66f3717b8..db16580b5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,8 +14,6 @@ class User attr_accessor :name, :uid, :email, :role_id, :jwt, :password, :provider_id, :client_id, :beta_tester, :errors def initialize(credentials, options={}) - logger = Logger.new(STDOUT) - if credentials.present? && options.fetch(:type, "").downcase == "basic" username, password = ::Base64.decode64(credentials).split(":", 2) payload = decode_auth_param(username: username, password: password)