Class: Ixtlan::Audit::Manager
- Inherits:
-
Object
- Object
- Ixtlan::Audit::Manager
- Includes:
- Slf4r::Logger
- Defined in:
- lib/ixtlan/audit/manager.rb
Defined Under Namespace
Classes: Log
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#dump_to_console ⇒ Object
Returns the value of attribute dump_to_console.
-
#keep_logs ⇒ Object
Returns the value of attribute keep_logs.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #daily_cleanup ⇒ Object
-
#initialize(model = nil, &block) ⇒ Manager
constructor
A new instance of Manager.
- #push(username, http_method, path, obj, user = nil) ⇒ Object
- #save_all(l = list) ⇒ Object
Constructor Details
#initialize(model = nil, &block) ⇒ Manager
Returns a new instance of Manager.
51 52 53 54 55 56 |
# File 'lib/ixtlan/audit/manager.rb', line 51 def initialize( model = nil, &block ) @model = model @keep_logs = 90 block.call( self ) if block @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
49 50 51 |
# File 'lib/ixtlan/audit/manager.rb', line 49 def block @block end |
#dump_to_console ⇒ Object
Returns the value of attribute dump_to_console.
49 50 51 |
# File 'lib/ixtlan/audit/manager.rb', line 49 def dump_to_console @dump_to_console end |
#keep_logs ⇒ Object
Returns the value of attribute keep_logs.
49 50 51 |
# File 'lib/ixtlan/audit/manager.rb', line 49 def keep_logs @keep_logs end |
#model ⇒ Object
Returns the value of attribute model.
49 50 51 |
# File 'lib/ixtlan/audit/manager.rb', line 49 def model @model end |
Instance Method Details
#daily_cleanup ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ixtlan/audit/manager.rb', line 121 def daily_cleanup return unless model now = DateTime.now if(@last_cleanup.nil? || @last_cleanup < (now - 1)) @last_cleanup = now begin delete_all( now - keep_logs ) logger.info "cleaned audit logs" rescue Exception => e logger.warn "error cleaning up audit logs: #{e.}" end end end |
#push(username, http_method, path, obj, user = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ixtlan/audit/manager.rb', line 79 def push( username, http_method, path, obj, user = nil ) if model = if obj.respond_to?( :errors ) && obj.errors.size > 0 "#{obj.class} - errors: " + obj.errors.collect{ |e| e }.join( '. ' ) elsif !obj.is_a?( String ) && obj.respond_to?( :collect ) if o = obj.first "#{o.class} - size: #{obj.size}" else "[ 0 ] - <EMPTY ARRAY>" end else obj.to_s end m = model.new( :http_method => http_method, :path => path, :message => , :login => username || '???' ) m.created_by = user if user && m.respond_to?( :created_by ) && user.respond_to?( :new? ) && !user.new? list << m logger.info( "[#{username}] #{http_method} #{path} #{}" ) if dump_to_console end list.last end |
#save_all(l = list) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ixtlan/audit/manager.rb', line 104 def save_all( l = list ) daily_cleanup l.each do |audit| begin audit.save if ( audit.respond_to?( :errors ) && audit.errors.size > 0 ) warn audit.errors.inspect end rescue => e warn "unexpected error - skip entry" warn e. warn audit.inspect end end list.clear end |