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 `(\w+)')?/o
CALLER_INDEX =
RUBY_PLATFORM[%r/^java/i] ? 1 : 2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

call-seq:

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

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/logging/log_event.rb', line 28

def initialize( logger, level, data, trace )
  @logger = logger
  @level = level
  @data = data
  @file = @line = @method = ''

  if trace
    t = Kernel.caller[CALLER_INDEX]
    return if t.nil?

    m = CALLER_RGXP.match(t)
    @file = m[1]
    @line = Integer(m[2])
    @method = m[3] unless m[3].nil?
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



45
46
47
# File 'lib/logging/log_event.rb', line 45

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



46
47
48
# File 'lib/logging/log_event.rb', line 46

def file
  @file
end

#levelObject

Returns the value of attribute level.



45
46
47
# File 'lib/logging/log_event.rb', line 45

def level
  @level
end

#lineObject (readonly)

Returns the value of attribute line.



46
47
48
# File 'lib/logging/log_event.rb', line 46

def line
  @line
end

#loggerObject

Returns the value of attribute logger.



45
46
47
# File 'lib/logging/log_event.rb', line 45

def logger
  @logger
end

#methodObject (readonly)

Returns the value of attribute method.



46
47
48
# File 'lib/logging/log_event.rb', line 46

def method
  @method
end