Skip to content

Commit

Permalink
Merge pull request #119 from DigitalNZ/pm/lograge
Browse files Browse the repository at this point in the history
LOGRAGE ACROSS ALL APPS
  • Loading branch information
paul-mesnilgrente authored Nov 13, 2019
2 parents 60fb895 + 105e8cc commit d075d97
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 64 deletions.
27 changes: 10 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@

source 'https://rubygems.org'

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end

gem 'aasm'
gem 'active_model_serializers', '~> 0.10.7'
gem 'activeresource', require: 'active_resource'
gem 'airbrake', '~> 7.2'
gem 'airbrake'
gem 'awesome_print', '~> 1.8'
gem 'aws-sdk-s3', '~> 1'
gem 'chronic'
gem 'elastic-apm'
gem 'figaro'
gem 'kaminari'
gem 'kaminari-mongoid'
gem 'lograge', '~> 0.11.2'
gem 'mongoid', '~> 7.0'
gem 'oai', git: 'https://github.com/boost/ruby-oai.git'
gem 'ougai', '~> 1.8'
gem 'parse-cron'
gem 'puma', '~> 3.7'
gem 'rails', '5.2.1'
gem 'responders'
gem 'sidekiq', '= 5.2.3'
gem 'sinatra', :require => nil
gem 'sinatra', require: nil
gem 'supplejack_common', git: 'https://github.com/DigitalNZ/supplejack_common.git', tag: 'v2.7.1'
# gem 'supplejack_common', path: '/webspace/supplejack/common'
gem 'elastic-apm'

gem 'whenever', require: false
gem 'rubocop', require: false

group :test do
gem 'cucumber-rails', require: false
Expand All @@ -40,17 +35,15 @@ group :test do
gem 'rspec-rails', '~> 3.6'
gem 'rspec-sidekiq'
gem 'timecop'
gem 'pry-byebug'
end

group :development do
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'pry'
gem 'pry-byebug'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
group :test, :development do
gem 'pry-byebug'
gem 'rubocop', require: false
end
27 changes: 20 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
airbrake (7.2.1)
airbrake-ruby (~> 2.5)
airbrake-ruby (2.8.2)
airbrake (9.5.0)
airbrake-ruby (~> 4.8)
airbrake-ruby (4.8.0)
rbtree3 (~> 0.5)
arel (9.0.0)
ast (2.4.0)
awesome_print (1.8.0)
aws-eventstream (1.0.1)
aws-partitions (1.142.0)
aws-sdk-core (3.46.2)
Expand Down Expand Up @@ -212,6 +214,11 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lograge (0.11.2)
actionpack (>= 4)
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -242,6 +249,9 @@ GEM
mini_portile2 (~> 2.3.0)
nokogumbo (2.0.1)
nokogiri (~> 1.8, >= 1.8.4)
oj (3.9.2)
ougai (1.8.2)
oj (~> 3.4)
parallel (1.12.1)
parse-cron (0.1.4)
parser (2.5.0.3)
Expand Down Expand Up @@ -293,7 +303,10 @@ GEM
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rbtree3 (0.5.0)
redis (3.3.5)
request_store (1.4.1)
rack (>= 1.4)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
Expand Down Expand Up @@ -385,9 +398,9 @@ DEPENDENCIES
aasm
active_model_serializers (~> 0.10.7)
activeresource
airbrake (~> 7.2)
airbrake
awesome_print (~> 1.8)
aws-sdk-s3 (~> 1)
byebug
chronic
cucumber-rails
database_cleaner
Expand All @@ -397,10 +410,11 @@ DEPENDENCIES
kaminari
kaminari-mongoid
listen (>= 3.0.5, < 3.2)
lograge (~> 0.11.2)
mongoid (~> 7.0)
oai!
ougai (~> 1.8)
parse-cron
pry
pry-byebug
puma (~> 3.7)
rails (= 5.2.1)
Expand All @@ -416,7 +430,6 @@ DEPENDENCIES
spring-watcher-listen (~> 2.0.0)
supplejack_common!
timecop
tzinfo-data
whenever

BUNDLED WITH
Expand Down
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
config.logger = ActiveSupport::TaggedLogging.new(CustomLogger::Logger.new(STDOUT))

config.log_level = :debug
# Raises error for missing translations
Expand Down
24 changes: 4 additions & 20 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = ENV['LOG_LEVEL'] || :info

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

Expand All @@ -61,19 +54,6 @@
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

ActionMailer::Base.delivery_method = :smtp
# Include your app's configuration here:
ActionMailer::Base.smtp_settings = {
Expand All @@ -85,4 +65,8 @@
}

config.action_mailer.default_url_options = { host: ENV['HOST'] }

config.log_level = ENV['LOG_LEVEL'] || :info
config.log_tags = [:request_id]
config.logger = ActiveSupport::TaggedLogging.new(CustomLogger::Logger.new(STDOUT))
end
24 changes: 4 additions & 20 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = ENV['LOG_LEVEL'] || :info

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

Expand All @@ -61,19 +54,6 @@
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

ActionMailer::Base.delivery_method = :smtp
# Include your app's configuration here:
ActionMailer::Base.smtp_settings = {
Expand All @@ -85,4 +65,8 @@
}

config.action_mailer.default_url_options = { host: ENV['HOST'] }

config.log_level = ENV['LOG_LEVEL'] || :info
config.log_tags = [:request_id]
config.logger = ActiveSupport::TaggedLogging.new(CustomLogger::Logger.new(STDOUT))
end
72 changes: 72 additions & 0 deletions config/environments/uat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# `config/secrets.yml.key`.
config.read_encrypted_secrets = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "sj_worker_5_1_4_#{Rails.env}"
config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

ActionMailer::Base.delivery_method = :smtp
# Include your app's configuration here:
ActionMailer::Base.smtp_settings = {
address: ENV['SMTP_ADDRESS'],
domain: ENV['SMTP_DOMAIN'],
port: ENV['SMTP_PORT'],
user_name: ENV['SMTP_USER_NAME'],
password: ENV['SMTP_PASSWORD']
}

config.action_mailer.default_url_options = { host: ENV['HOST'] }

config.log_level = ENV['LOG_LEVEL'] || :info
config.log_tags = [:request_id]
config.logger = ActiveSupport::TaggedLogging.new(CustomLogger::Logger.new(STDOUT))
end
21 changes: 21 additions & 0 deletions config/initializers/lograge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

Rails.application.configure do
config.lograge.enabled = true
config.lograge.ignore_actions = ['StatusController#index']
config.lograge.formatter = Class.new do |fmt|
def fmt.call(data)
{ msg: 'Request', request: data }
end
end

config.lograge.custom_options = lambda do |event|
{
request_id: event.payload[:request_id],
params: event.payload[:params].except('controller', 'action', 'format', 'id'),
time: event.time
}
end

config.lograge.custom_payload { |controller| { request_id: controller.request.request_id } }
end
36 changes: 36 additions & 0 deletions lib/custom_logger/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

unless Rails.env.test?
module ActiveSupport
module TaggedLogging
module Formatter
def call(severity, time, progname, data)
data = { msg: data.to_s } unless data.is_a?(Hash)
tags = current_tags
data[:tags] = tags if tags.present?
_call(severity, time, progname, data)
end
end
end
end
end

module CustomLogger
class Logger < Ougai::Logger
include ActiveSupport::LoggerThreadSafeLevel
include LoggerSilence

def initialize(*args)
super
after_initialize if respond_to? :after_initialize
end

def create_formatter
if Rails.env.development? || Rails.env.test?
Ougai::Formatters::Readable.new
else
Ougai::Formatters::Bunyan.new
end
end
end
end

0 comments on commit d075d97

Please sign in to comment.