Module: Rofl

Defined in:
lib/rofl.rb

Overview

little happy logger module

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debugnameObject

Returns the value of attribute debugname.



6
7
8
# File 'lib/rofl.rb', line 6

def debugname
  @debugname
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/rofl.rb', line 6

def logger
  @logger
end

Instance Method Details

#dlog(text = "debug") ⇒ Object

debug message



42
43
44
45
# File 'lib/rofl.rb', line 42

def dlog text="debug"
  rofl_logger_check #check if logger is setup
  @logger.debug "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
end

#elog(text = "error") ⇒ Object

error message



27
28
29
30
# File 'lib/rofl.rb', line 27

def elog text="error" 
  rofl_logger_check #check if logger is setup
  @logger.error "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
end

#ilog(text = "info") ⇒ Object

info message



37
38
39
40
# File 'lib/rofl.rb', line 37

def ilog text="info"
  rofl_logger_check #check if logger is setup
  @logger.info "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
end

#rofl?(object = self) ⇒ Boolean

check if we or an object are ready to rofl

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/rofl.rb', line 56

def rofl? object=self
  has_rofl = (defined? object.rofl?).eql? "method"
  dlog "object of class: #{object.class} is rock'n'rofl." if has_rofl
  return has_rofl
end

#rofl_logger_checkObject

check if there already is a logger, kind of a constructor



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rofl.rb', line 9

def rofl_logger_check
  if @logger.nil?
    #to stop output from getting messy, we use a logger
    @logger = Logger.new(STDOUT)
    @logger.level = Logger::DEBUG
    #@logger.datetime_format = "%Y-%m-%d %H:%M:%S" #useful for logging to a file
    @logger.datetime_format = "%H:%M:%S" #useful for debugging
    @debugname = self.class if @debugname.nil? #only used to inform the user
    @tracing = false
    #enable tracing
    if @tracing
      require 'rofl_trace'
      include RoflTrace
      rofl_enable_trace
    end
  end
end

#rofl_meth_traceObject

get method call trace



47
48
49
50
51
52
53
54
# File 'lib/rofl.rb', line 47

def rofl_meth_trace
  skip = 2 #indicates how many items we skip in the execution stack trace
  call_trace = caller(skip)
  last_meth = call_trace[0][/\`.*?\'/]
  last_meth_name = "notrace"
  last_meth_name = last_meth.delete("\`").delete("\'") unless last_meth.nil?
  return last_meth_name
end

#wlog(text = "warning") ⇒ Object

warning



32
33
34
35
# File 'lib/rofl.rb', line 32

def wlog text="warning"
  rofl_logger_check #check if logger is setup
  @logger.warning "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
end