-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LTI-404: add support for multi-logging (#344)
- Loading branch information
Showing
8 changed files
with
88 additions
and
13 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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
Fixnum = Integer unless defined?(Integer) |
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'syslog/logger' | ||
require_relative '../../lib/custom_logger' | ||
|
||
# Initialize stdout logger | ||
stdout_appender = Logging.appenders.stdout( | ||
layout: Logging.layouts.pattern( | ||
pattern: '[%d] %-5l %c: %m\n', | ||
date_pattern: '%Y-%m-%d %H:%M:%S' | ||
) | ||
) | ||
|
||
Logging.logger.root.appenders = stdout_appender | ||
|
||
# Initialize remote logger (E.g for Papertrail) | ||
if ENV['RAILS_LOG_REMOTE_NAME'] && ENV['RAILS_LOG_REMOTE_PORT'] | ||
require 'remote_syslog_logger' | ||
remote_logger = RemoteSyslogLogger.new( | ||
ENV['RAILS_LOG_REMOTE_NAME'], | ||
ENV['RAILS_LOG_REMOTE_PORT'].to_i, | ||
program: ENV['RAILS_LOG_REMOTE_TAG'] || "bbb-lti-broker-#{ENV['RAILS_ENV']}" | ||
) | ||
Rails.logger.extend(ActiveSupport::Logger.broadcast(remote_logger)) | ||
end | ||
|
||
# Set the log level from the environment variable or default to debug | ||
log_level = ENV['LOG_LEVEL']&.downcase || 'debug' | ||
Logging.logger.root.level = log_level |
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'logging' | ||
require 'active_support/tagged_logging' | ||
|
||
class CustomLogger < ActiveSupport::Logger | ||
def initialize(_logger_name) | ||
# Define the log file path based on the Rails environment | ||
log_file_path = Rails.root.join('log', "#{Rails.env}.log") | ||
|
||
# Initialize the logger to write to the environment-specific log file | ||
super(log_file_path) | ||
|
||
self.formatter = proc do |severity, datetime, progname, msg| | ||
"[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}] #{severity} #{progname}: #{msg}\n" | ||
end | ||
end | ||
end |