Skip to content

Commit a429233

Browse files
authored
Merge pull request #284 from seq-code/production-json-logging
Use semantic JSON logging in production
2 parents 8b31d8e + feed7f2 commit a429233

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ gem 'puma', '~> 5.6'
3535
gem 'rails', '~> 6.1'
3636
gem 'rack-attack'
3737
gem 'rack-cors'
38+
gem 'rails_semantic_logger', '~> 4.20'
3839
gem 'redcarpet', '~> 3.5'
3940
gem 'redirect_safely', '~> 1.0'
4041
gem 'rexml'

Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ GEM
286286
rails-html-sanitizer (1.7.0)
287287
loofah (~> 2.25)
288288
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)
289+
rails_semantic_logger (4.20.0)
290+
rack
291+
railties (>= 5.1)
292+
semantic_logger (~> 4.16)
289293
railties (6.1.7.10)
290294
actionpack (= 6.1.7.10)
291295
activesupport (= 6.1.7.10)
@@ -382,6 +386,8 @@ GEM
382386
rexml (~> 3.2, >= 3.2.5)
383387
rubyzip (>= 1.2.2, < 4.0)
384388
websocket (~> 1.0)
389+
semantic_logger (4.18.0)
390+
concurrent-ruby (~> 1.0)
385391
semantic_range (3.1.1)
386392
serrano (1.7)
387393
faraday (~> 2.14, >= 2.14.1)
@@ -499,6 +505,7 @@ DEPENDENCIES
499505
rack-attack
500506
rack-cors
501507
rails (~> 6.1)
508+
rails_semantic_logger (~> 4.20)
502509
rdoc
503510
redcarpet (~> 3.5)
504511
redirect_safely (~> 1.0)

config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Application < Rails::Application
1414
# Boolean handling of SQLite3
1515
config.active_record.sqlite3&.represent_boolean_as_integer = true
1616

17+
config.semantic_logger.application = 'seqcode-registry'
18+
config.semantic_logger.environment = Rails.env
19+
1720
# Settings in config/environments/* take precedence over those specified here.
1821
# Application configuration can go into files in config/initializers
1922
# -- all .rb files in that directory are automatically loaded after loading

config/environments/production.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
config.log_level = :warn
5757

5858
# Prepend all log lines with the following tags.
59-
config.log_tags = [ :request_id ]
59+
config.log_tags = { request_id: :request_id }
6060

6161
# Use a different cache store in production.
6262
# config.cache_store = :mem_cache_store
@@ -91,17 +91,11 @@
9191
# Send deprecation notices to registered listeners.
9292
config.active_support.deprecation = :notify
9393

94-
# Use default logging formatter so that PID and timestamp are not suppressed.
95-
config.log_formatter = ::Logger::Formatter.new
96-
97-
# Use a different logger for distributed setups.
98-
# require 'syslog/logger'
99-
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
94+
config.rails_semantic_logger.format = :json
10095

10196
if ENV['RAILS_LOG_TO_STDOUT'].present?
102-
logger = ActiveSupport::Logger.new(STDOUT)
103-
logger.formatter = config.log_formatter
104-
config.logger = ActiveSupport::TaggedLogging.new(logger)
97+
config.rails_semantic_logger.add_file_appender = false
98+
config.semantic_logger.add_appender(io: STDOUT, formatter: :json)
10599
end
106100

107101
# Do not dump schema after migrations.

0 commit comments

Comments
 (0)