-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from DigitalNZ/pm/lograge
LOGRAGE ACROSS ALL APPS
- Loading branch information
Showing
8 changed files
with
168 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |