Skip to content

Commit

Permalink
use logstash format for all logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 13, 2019
1 parent c34f3d3 commit 817f747
Show file tree
Hide file tree
Showing 37 changed files with 101 additions and 103 deletions.
4 changes: 2 additions & 2 deletions app/controllers/client_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]) }
Expand All @@ -131,15 +131,15 @@ 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

# 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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down Expand Up @@ -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))
Expand All @@ -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?

Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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?

Expand All @@ -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
Expand Down Expand Up @@ -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?

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/metadata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/provider_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -247,15 +247,15 @@ 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

# 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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]) }
Expand All @@ -158,15 +158,15 @@ 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

# 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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 817f747

Please sign in to comment.