30 lines
894 B
Ruby
30 lines
894 B
Ruby
require 'active_support'
|
|
|
|
if CANVAS_RAILS2
|
|
ActiveSupport::BufferedLogger.class_eval do
|
|
alias :quietly :silence
|
|
end
|
|
end
|
|
|
|
class CanvasLogger < ActiveSupport::BufferedLogger
|
|
attr_reader :log_path
|
|
|
|
def initialize(log_path, level = DEBUG, options = {})
|
|
super(log_path, level)
|
|
@log_path = log_path
|
|
@skip_thread_context = options[:skip_thread_context]
|
|
end
|
|
|
|
def add(severity, message=nil, progname=nil, &block)
|
|
return if level > severity
|
|
message = (message || (block && block.call) || progname).to_s
|
|
# If a newline is necessary then create a new message ending with a newline.
|
|
# Ensures that the original message is not mutated.
|
|
unless @skip_thread_context
|
|
context = Thread.current[:context] || {}
|
|
message = "[#{context[:session_id] || "-"} #{context[:request_id] || "-"}] #{message}"
|
|
end
|
|
super(severity, message, progname)
|
|
end
|
|
end
|