Class: Mole::Moler

Inherits:
Object
  • Object
show all
Defined in:
lib/mole/moler.rb

Class Method Summary collapse

Class Method Details

.check_it(context, user_id, args) ⇒ Object

log an unchecked exception. Moler will look at the MOle configuration to see if this event should be persisted to the db or sent out to the logger.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mole/moler.rb', line 14

def check_it( context, user_id, args )                                            
  return unless ::Mole.moleable?   
  # If exception is given record the first couple of frames
  if args[:boom]
    args[:trace] = dump_stack( args[:boom] )
    args[:boom]  = truncate( args[:boom].to_s )
  end        
  if ::Mole.persistent?             
    MoleLog.log_it( context, MoleFeature::find_exception_feature( ::Mole.application ), user_id, args )             
  else                                                                            
    ::Mole.logger.log_it( context, "Exception", user_id, args ) 
  end          
  # Send out email notification if requested
  Mole::EMole.deliver_exception_alerts( context, user_id, args ) if args[:email] and args[:email] == true        
end

.dump_stack(boom) ⇒ Object

dumps partial stack



65
66
67
68
# File 'lib/mole/moler.rb', line 65

def dump_stack( boom )
  return truncate( boom.backtrace[0] ) if boom.backtrace.size == 1
  buff = boom.backtrace[0...3].join( "-" )
end

.mole_it(context, feature, user_id, args) ⇒ Object

log a mole feature occurence.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mole/moler.rb', line 43

def mole_it(context, feature, user_id, args)    
  return unless ::Mole.moleable?        
  if ::Mole.persistent?
    MoleLog.log_it( context, MoleFeature::find_or_create_feature( feature, ::Mole.application, context.class.name ), user_id, args )
  else
    ::Mole.logger.log_it( context, feature, user_id, args )
  end
  # Send out email notification if requested   
  if args[:email] and args[:email] == true 
    args[:feature] = feature
    Mole::EMole.deliver_feature_alerts( context, user_id, args )                         
  end
end

.perf_it(context, user_id, args) ⇒ Object

log performance occurence.



31
32
33
34
35
36
37
38
39
40
# File 'lib/mole/moler.rb', line 31

def perf_it( context, user_id, args )
  return unless ::Mole.moleable?        
  if ::Mole.persistent?
    MoleLog.log_it( context, MoleFeature::find_performance_feature( ::Mole.application ), user_id, args )
  else
    ::Mole.logger.log_it( context, "Performance", user_id, args )
  end
  # Send out email notification if requested
  Mole::EMole.deliver_perf_alerts( context, user_id, args ) if args[:email] and args[:email] == true                
end

.truncate(text, length = 200, truncate_string = "...") ⇒ Object

Truncate



58
59
60
61
62
# File 'lib/mole/moler.rb', line 58

def truncate(text, length = 200, truncate_string = "...")
  return "" if text.nil?
  l = length - truncate_string.chars.length
  text.chars.length > length ? (text.chars[0...l] + truncate_string).to_s : text
end