Skip to content
Snippets Groups Projects
Commit 741e232a authored by iaibrys's avatar iaibrys
Browse files

Add user to logging.

parent aecfc4e5
Branches
No related tags found
No related merge requests found
Pipeline #165 passed
......@@ -17,6 +17,15 @@ require 'rails/test_unit/railtie'
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
# Simple formatter which only displays the message.
class EnoteFormatter < ::Logger::Formatter
# This method is invoked when a log event occurs
def call(severity, timestamp, progname, msg)
# Format % [severity[0..0], format_datetime(timestamp), $$, severity, progname, msg2str(msg)]
"#{severity[0..0]} [#{format_datetime(timestamp)}] #{msg2str(msg)}\n"
end
end
module DTUCourseWebsite
##
# Application
......@@ -41,7 +50,8 @@ module DTUCourseWebsite
# add service objects
config.autoload_paths += Dir["#{config.root}/app/services/**/"]
config.autoload_paths += Dir["#{config.root}/app/responders/**/"]
config.autoload_paths += Dir["#{config.root}/lib**/"]
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.eager_load_paths += Dir["#{config.root}/lib/**/"]
DtuCore::app_init config
......@@ -54,17 +64,23 @@ module DTUCourseWebsite
g.test_framework :rspec
end
log_level = String(ENV.fetch('LOG_LEVEL') { config.deployment_environment[:public_facing] ? 'info' : 'debug' }).upcase
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(log_level)
config.log_level = log_level
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = EnoteFormatter.new #config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.lograge.enabled = true
# log rage doesn't log params by default, so add this to do so.
unless Rails.env.production?
# log rage doesn't log params by default.
# For production, though, the params can be HUGE (e.g. webgazer datapoints, so let's be cautious)
config.lograge.custom_options = lambda do |event|
exceptions = %w[controller action format id]
{ params: event.payload[:params].except(*exceptions) }
exceptions = %w[controller action format id points]
{
params: event.payload[:params].except(*exceptions),
time: event.time
}
end
end
if config.lograge.enabled
class ActionDispatch::DebugExceptions
alias old_log_error log_error
......
......@@ -49,7 +49,19 @@ Rails.application.configure do
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = config.deployment_environment[:public_facing] ? :info : :debug
config.log_level = String(ENV.fetch('LOG_LEVEL') { config.deployment_environment[:public_facing] ? 'info' : 'debug' }).upcase
# Prepend all log lines with the following tags.
config.log_tags = [:request_id,
# http://blog.simontaranto.com/post/2018-05-18-better-rails-logs-current-user-request-context.html/
->(req){
if user_id = CasTaggedLogger.extract_user_id_from_request(req)
user_id.to_s
else
"?"
end
}
]
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
......
Subproject commit 601f75c4374ceceae3ba57e2f8bb5a9d81e658d2
Subproject commit 4784322436b2411c8f15c1a1366aa13ffd59bb55
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment