Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantic logging #213

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ gem "traject", require: false # only for indexing
# Semantic logging?
gem "awesome_print"
gem "semantic_logger"
gem "rails_semantic_logger"

gem "lograge", ">=0.11.1"
# gem "lograge", ">=0.11.1"

# Contacts Email
gem "mail_form", "~>1.7"
Expand Down
15 changes: 6 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ GEM
llhttp-ffi (0.4.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)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -274,6 +269,10 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
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)
Expand All @@ -291,8 +290,6 @@ GEM
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)
rack
Expand Down Expand Up @@ -355,7 +352,7 @@ GEM
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)
Expand Down Expand Up @@ -464,7 +461,6 @@ DEPENDENCIES
jquery-rails
kaminari (>= 1.2.1)
listen
lograge (>= 0.11.1)
loofah (>= 2.3.1)
mail_form (~> 1.7)
middle_english_dictionary!
Expand All @@ -480,6 +476,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)
Expand Down
34 changes: 13 additions & 21 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "rails/all"
require "json"
require_relative "../lib/dromedary/services"
require_relative "../lib/dromedary/abbreviated_json_format"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down Expand Up @@ -44,30 +45,21 @@ class Application < Rails::Application
config.blacklight_url = Dromedary::Services[:solr_embedded_auth_url]

config.log_level = :info

config.lograge.enabled = false

# 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.rails_semantic_logger.add_file_appender = false
config.semantic_logger.backtrace_level = :error
config.log_tags = {
ip: :remote_ip
}
# Just use the standard :json logger and worry about filtering on the receiving end
# config.rails_semantic_logger.format = Dromedary::AbbreviatedJsonFormat.new
config.rails_semantic_logger.format = :json
config.semantic_logger.add_appender(io: $stdout)

config.active_record.yaml_column_permitted_classes = [ActiveSupport::HashWithIndifferentAccess]

# config.log_tags = {
# ip: :remote_ip,
# }
config.log_tags = {
ip: :remote_ip,
}
# config.rails_semantic_logger.quiet_assets = true
# config.rails_semantic_logger.format = :json

Expand Down
2 changes: 0 additions & 2 deletions config/load_local_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def config
end

def hyp_to_bibid(collection: Dromedary::Services[:solr_current_collection])
logger.info "Trying to get hyp_to_bibid for collection #{collection}"
current_real_collection_name = underlying_real_collection_name(coll: collection)
logger.info "Real collection name identified as #{current_real_collection_name}"
if @recorded_real_collection_name != current_real_collection_name
@hyp_to_bibid = MedInstaller::HypToBibId.get_from_solr(collection: collection)
@recorded_real_collection_name = current_real_collection_name
Expand Down
30 changes: 30 additions & 0 deletions lib/dromedary/abbreviated_json_format.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "rails_semantic_logger"

module Dromedary
class AbbreviatedJsonFormat < SemanticLogger::Formatters::Json


def application
"MED"
end

def name; end

def host; end

def duration_ms; end

def pid; end

def level_index; end

def thread_name; end

def db_runtime; end

def process_info; end

def status_message; end

end
end
7 changes: 3 additions & 4 deletions lib/med_installer/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ def process_info
end
end

Formatter = MEDFormatter.new(time_format: "%Y-%m-%d:%H:%M:%S")
SemanticLogger.add_appender(io: $stderr, level: :info, formatter: Formatter)
SemanticLogger.add_appender(io: $stdout, formatter: :color)
# Formatter = MEDFormatter.new(time_format: "%Y-%m-%d:%H:%M:%S")
LOGGER = SemanticLogger["Dromedary"]

def logger
if defined? Rails
Rails.logger
else
LOGGER
end
LOGGER
end
end
end
Loading