Class: Logging::LogEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/logging/log_event.rb

Overview

This class defines a logging event.

Constant Summary collapse

CALLER_RGXP =

Regular expression used to parse out caller information

  • $1 == filename

  • $2 == line number

  • $3 == method name (might be nil)

%r/([-\.\/\(\)\w]+):(\d+)(?::in `([^']+)')?/o
CALLER_INDEX =

CALLER_INDEX = 2

(defined?(RUBY_ENGINE) && RUBY_ENGINE[%r/^rbx/i])) ? 1 : 2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, level, data, caller_tracing) ⇒ LogEvent

call-seq:

LogEvent.new( logger, level, [data], caller_tracing )

Creates a new log event with the given logger name, numeric level, array of data from the user to be logged, and boolean caller_tracing flag. If the caller_tracing flag is set to true then Kernel::caller will be invoked to get the execution trace of the logging method.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/logging/log_event.rb', line 29

def initialize( logger, level, data, caller_tracing )
  self.logger = logger
  self.level  = level
  self.data   = data
  self.time   = Time.now.freeze

  if caller_tracing
    stack = Kernel.caller[CALLER_INDEX]
    return if stack.nil?

    match = CALLER_RGXP.match(stack)
    self.file = match[1]
    self.line = Integer(match[2])
    self.method_name = match[3] unless match[3].nil?

    if (bp = ::Logging.basepath) && !bp.empty? && file.index(bp) == 0
      self.file = file.slice(bp.length + 1, file.length - bp.length)
    end
  else
    self.file = self.line = self.method_name = ''
  end
end

Instance Attribute Details

#dataObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def data
  @data
end

#fileObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def file
  @file
end

#levelObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def level
  @level
end

#lineObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def line
  @line
end

#loggerObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def logger
  @logger
end

#method_nameObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def method_name
  @method_name
end

#timeObject

:startdoc:



19
20
21
# File 'lib/logging/log_event.rb', line 19

def time
  @time
end