module ContextLogger
Constants
- ALL_DESTINATIONS
- DEFAULTS
- SEVERITY_TYPES
Public Class Methods
destinations()
click to toggle source
# File lib/context_logger.rb, line 55 def self.destinations return @destinations end
options()
click to toggle source
# File lib/context_logger.rb, line 42 def self.options return @options end
set_destinations(_destinations)
click to toggle source
# File lib/context_logger.rb, line 46 def self.set_destinations(_destinations) if _destinations == :all @destinations = ALL_DESTINATIONS.clone return end @destinations = _destinations.select{|k, v| ALL_DESTINATIONS[k] and v} end
setup(options)
click to toggle source
# File lib/context_logger.rb, line 38 def self.setup(options) @options = (@options || {}).merge(options) end
Private Class Methods
db_log_columns()
click to toggle source
# File lib/context_logger.rb, line 96 def self.db_log_columns return @db_log_columns if @db_log_columns @db_log_columns = {} if ::ContextLog.respond_to?(:columns) ::ContextLog.columns.each{|column| @db_log_columns[column.name.to_sym] = true} elsif ::ContextLog.respond_to?(:fields) ::ContextLog.fields.keys.each{|column| @db_log_columns[column.to_sym] = true} end return @db_log_columns end
log(params)
click to toggle source
# File lib/context_logger.rb, line 71 def self.log(params) params_with_defaults = options.merge(params.reject{|_, v| v.nil?}) destinations.each do |log_destination, _| self.send(log_destination, params_with_defaults) end end
log_file_path(current_context)
click to toggle source
# File lib/context_logger.rb, line 66 def self.log_file_path(current_context) file_name = current_context.to_s.downcase.gsub(/ /, '_').gsub(/[^0-9a-z_]/, '') return "#{logs_folder}/#{file_name}.log" end
logger_of_context(current_context)
click to toggle source
# File lib/context_logger.rb, line 79 def self.logger_of_context(current_context) @context_loggers[current_context] ||= ::Logger.new(log_file_path(current_context)) end
logs_folder()
click to toggle source
# File lib/context_logger.rb, line 61 def self.logs_folder # TODO: set the path from config @logs_folder ||= "#{Rails.root}/log" end
write_context_log(params_with_defaults)
click to toggle source
# File lib/context_logger.rb, line 87 def self.write_context_log(params_with_defaults) logger_instance = logger_of_context(params_with_defaults[:context].to_sym) logger_instance.send params_with_defaults[:severity].to_sym, params_with_defaults.except(:context, :severity) end
write_db_log(params_with_defaults)
click to toggle source
# File lib/context_logger.rb, line 92 def self.write_db_log(params_with_defaults) ::ContextLog.create(params_with_defaults.select{|k, _| db_log_columns[k]}) end
write_rails_log(params_with_defaults)
click to toggle source
# File lib/context_logger.rb, line 83 def self.write_rails_log(params_with_defaults) Rails.logger.send params_with_defaults[:severity].to_sym, params_with_defaults.except(:severity) end