Sha256: 628ca7df0b5158957306d36e07f3e1fad7e1e2eebe14dbb7456c1010713d05bf

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# $Id: log_event.rb 37 2007-10-26 19:12:44Z tim_pease $

module Logging

  # This class defines a logging event.
  #
  class LogEvent

    # :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
    # :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 )
      @logger = logger
      @level = level
      @data = data
      @file = @line = @method = ''

      if trace
        t = Kernel.caller(3)[0]
        break if t.nil?

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

    attr_accessor :logger, :level, :data
    attr_reader :file, :line, :method

  end  # class LogEvent
end  # module Logging

# EOF

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logging-0.5.0 lib/logging/log_event.rb
logging-0.5.1 lib/logging/log_event.rb