Class: Logging::LogEvent

Inherits:
Struct
  • 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 =

CALLER_INDEX = 2

((defined? JRUBY_VERSION and JRUBY_VERSION[%r/^1.6/]) or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/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.



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

def initialize( logger, level, data, trace )
  f = l = m = ''

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

    match = CALLER_RGXP.match(stack)
    f = match[1]
    l = Integer(match[2])
    m = match[3] unless match[3].nil?
  end

  super(logger, level, data, Time.now, f, l, m)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



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

def data
  @data
end

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



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

def file
  @file
end

#levelObject

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



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

def level
  @level
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



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

def line
  @line
end

#loggerObject

Returns the value of attribute logger

Returns:

  • (Object)

    the current value of logger



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

def logger
  @logger
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



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

def method
  @method
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



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

def time
  @time
end