Module: MongodbLogger::Base
- Extended by:
- Config
- Defined in:
- lib/mongodb_logger.rb
Instance Attribute Summary
Attributes included from Config
#disabled, #on_log_exception
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Config
configure
Class Method Details
.included(base) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/mongodb_logger.rb', line 15
def self.included(base)
base.class_eval do
if defined?(around_action)
around_action :enable_mongodb_logger
else
around_filter :enable_mongodb_logger
end
end
end
|
Instance Method Details
#enable_mongodb_logger ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/mongodb_logger.rb', line 25
def enable_mongodb_logger
return yield unless Rails.logger.respond_to?(:mongoize)
f_session = (request.respond_to?(:session) ? request.session : session)
Rails.logger.mongoize({
method: request.method,
action: action_name,
controller: controller_name,
path: request.path,
url: request.url,
params: (request.respond_to?(:filtered_parameters) ? request.filtered_parameters : params),
session: mongo_fix_session_keys(f_session),
ip: request.remote_ip
}) { yield }
end
|
#mongo_fix_session_keys(session = {}) ⇒ Object
session keys can be with dots. It is invalid keys for BSON
40
41
42
43
44
45
46
|
# File 'lib/mongodb_logger.rb', line 40
def mongo_fix_session_keys(session = {})
new_session = Hash.new
session.to_hash.each do |i, j|
new_session[i.gsub(/\./i, "|")] = j.inspect
end unless session.empty?
new_session
end
|