Class: Ixtlan::UserLogger
- Inherits:
-
Object
- Object
- Ixtlan::UserLogger
- Defined in:
- lib/ixtlan/user_logger.rb
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(arg) ⇒ UserLogger
constructor
A new instance of UserLogger.
- #log(controller, message = nil, &block) ⇒ Object
- #log_action(controller, message = nil) ⇒ Object
- #log_user(user, message = nil, &block) ⇒ Object
Constructor Details
#initialize(arg) ⇒ UserLogger
Returns a new instance of UserLogger.
7 8 9 |
# File 'lib/ixtlan/user_logger.rb', line 7 def initialize(arg) @logger = Slf4r::LoggerFacade.new(arg) end |
Instance Method Details
#log(controller, message = nil, &block) ⇒ Object
20 21 22 |
# File 'lib/ixtlan/user_logger.rb', line 20 def log(controller, = nil, &block) log_user(login_from(controller), , &block) end |
#log_action(controller, message = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ixtlan/user_logger.rb', line 24 def log_action(controller, = nil) log_user(login_from(controller)) do as_xml = controller.response.content_type == 'application/xml' ? " - xml" : "" if controller.params[:controller] audits = controller.instance_variable_get("@#{controller.params[:controller].to_sym}") if(audits) "#{controller.params[:controller]}##{controller.params[:action]} #{audits.model.to_s.plural}[#{audits.size}]#{as_xml}#{}" else audit = controller.instance_variable_get("@#{controller.params[:controller].singular.to_sym}") if(audit) errors = if(audit.respond_to?(:errors) && !audit.errors.empty?) " - errors: " + audit.errors..join(", ") end audit_log = audit.respond_to?(:to_log) ? audit.to_log : "#{audit.model}(#{audit.key})" "#{controller.params[:controller]}##{controller.params[:action]} #{audit_log}#{as_xml}#{}#{errors}" else "#{controller.params[:controller]}##{controller.params[:action]}#{as_xml}#{}" end end else "params=#{controller.params.inspect}#{}" end end end |
#log_user(user, message = nil, &block) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/ixtlan/user_logger.rb', line 49 def log_user(user, = nil, &block) user ||= "???" msg = "#{}#{block.call if block}" if AUDIT AUDIT.new(:date => DateTime.now, :message => msg, :login => user).push end @logger.info {"[#{user}] #{msg}" } end |