Sha256: 231e7eb5ce7d89c0406b19c8e29ccd4d8cce694d351d7b92c3790a81bf0b53e0

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

module Logging

  # This class defines a logging event.
  #
  LogEvent = Struct.new( :logger, :level, :data, :time, :file, :line, :method ) {
    # :stopdoc:

    # Regular expression used to parse out caller information
    #
    # * $1 == filename
    # * $2 == line number
    # * $3 == method name (might be nil)
    CALLER_RGXP = %r/([\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
    CALLER_INDEX = 2
    #CALLER_INDEX = RUBY_PLATFORM[%r/^java/i] ? 1 : 2
    # :startdoc:

    # 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.
    #
    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
  }
end  # module Logging

# EOF

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
TwP-logging-1.2.0 lib/logging/log_event.rb
TwP-logging-1.2.2 lib/logging/log_event.rb
logging-1.4.3 lib/logging/log_event.rb
sgeorgi-logging-1.4.2 lib/logging/log_event.rb
logging-1.4.2 lib/logging/log_event.rb
logging-1.4.1 lib/logging/log_event.rb
logging-1.4.0 lib/logging/log_event.rb
redcar-0.3.1dev lib/logging/lib/logging/log_event.rb
redcar-0.3.0dev lib/logging/lib/logging/log_event.rb
logging-1.3.0 lib/logging/log_event.rb
redcar-0.2.9dev lib/logging/lib/logging/log_event.rb
logging-1.2.3 lib/logging/log_event.rb
logging-1.2.2 lib/logging/log_event.rb
logging-1.2.0 lib/logging/log_event.rb
logging-1.2.1 lib/logging/log_event.rb