Skip to content

Commit

Permalink
adds semantic logger; replaces Rack::Logger for Sinatras logger
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Jul 1, 2024
1 parent 54690d0 commit e209620
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "yabeda-puma-plugin"
gem "yabeda-prometheus"
gem "canister"
gem "rackup"
gem "semantic_logger"

group :development do
gem "sinatra-contrib"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ GEM
ruby-next-core (1.0.3)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
semantic_logger (4.15.0)
concurrent-ruby (~> 1.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -170,6 +172,7 @@ DEPENDENCIES
rack-test
rackup
rspec
semantic_logger
simplecov
sinatra
sinatra-contrib
Expand Down
3 changes: 3 additions & 0 deletions catalog-browse.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "sinatra"
require "sinatra/reloader" if development?
require "sinatra/custom_logger"
require "byebug" if development?

require "yaml"
Expand All @@ -20,6 +21,8 @@
require_relative "lib/models/search_dropdown"
require_relative "lib/models/datastores"

set :logger, S.logger

CatalogSolrClient.configure do |config|
config.solr_url = S.biblio_solr
end
Expand Down
19 changes: 19 additions & 0 deletions lib/services.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "canister"
require "semantic_logger"

Services = Canister.new
S = Services
Expand All @@ -24,3 +25,21 @@
].each do |e|
Services.register(e.downcase.to_sym) { ENV[e] }
end

S.register(:log_stream) do
$stdout.sync = true
$stdout
end

S.register(:logger) do
SemanticLogger["catalog-browse"]
end

case ENV["APP_ENV"]
when "production"
SemanticLogger.add_appender(io: S.log_stream, level: :info, formatter: :json)
when "test" # explicitly don't wnat an appender when running tests
nil
else
SemanticLogger.add_appender(io: S.log_stream, level: :info, formatter: :color)
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "climate_control"
SimpleCov.start
ENV["RACK_ENV"] = "test"
ENV["APP_ENV"] = "test"
require File.expand_path "../../catalog-browse.rb", __FILE__
module RSpecMixin
include Rack::Test::Methods
Expand Down

0 comments on commit e209620

Please sign in to comment.