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.
-
#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 |
#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
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ixtlan/audit/manager.rb', line 114 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ixtlan/audit/manager.rb', line 75 def push( username, http_method, path, obj, user = nil ) if model = if !obj.is_a?( String ) && obj.respond_to?( :collect ) if o = obj.first "#{o.class}[ #{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 end list.last end |
#save_all(l = list) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ixtlan/audit/manager.rb', line 97 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 |