Sha256: 8a0b819d358a53122bb669b039d8824f1a059582b6960db0f6053a22114df02c

Contents?: true

Size: 918 Bytes

Versions: 15

Compression:

Stored size: 918 Bytes

Contents

# -*- coding: binary -*-
module Rex
module Logging
module Sinks

###
#
# This class implements the LogSink interface and backs it against a
# file on disk.
#
###
class Flatfile

  include Rex::Logging::LogSink

  #
  # Creates a flatfile log sink instance that will be configured to log to
  # the supplied file path.
  #
  def initialize(file)
    self.fd = File.new(file, "a")
  end

  def cleanup # :nodoc:
    fd.close
  end

  def log(sev, src, level, msg, from) # :nodoc:
    if (sev == LOG_RAW)
      fd.write(msg)
    else
      code = 'i'

      case sev
        when LOG_DEBUG
          code = 'd'
        when LOG_ERROR
          code = 'e'
        when LOG_INFO
          code = 'i'
        when LOG_WARN
          code = 'w'
      end
      fd.write("[#{get_current_timestamp}] [#{code}(#{level})] #{src}: #{msg}\n")
    end

    fd.flush
  end

protected

  attr_accessor :fd # :nodoc:

end

end end end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
rex-2.0.13 lib/rex/logging/sinks/flatfile.rb
rex-2.0.12 lib/rex/logging/sinks/flatfile.rb
rex-2.0.11 lib/rex/logging/sinks/flatfile.rb
rex-2.0.10 lib/rex/logging/sinks/flatfile.rb
rex-2.0.9 lib/rex/logging/sinks/flatfile.rb
rex-2.0.8 lib/rex/logging/sinks/flatfile.rb
rex-2.0.7 lib/rex/logging/sinks/flatfile.rb
rex-2.0.5 lib/rex/logging/sinks/flatfile.rb
rex-2.0.4 lib/rex/logging/sinks/flatfile.rb
dstruct-0.0.1 lib/rex/logging/sinks/flatfile.rb
rex-2.0.3 lib/rex/logging/sinks/flatfile.rb
librex-0.0.999 lib/rex/logging/sinks/flatfile.rb
rex-2.0.2 lib/rex/logging/sinks/flatfile.rb
librex-0.0.71 lib/rex/logging/sinks/flatfile.rb
librex-0.0.70 lib/rex/logging/sinks/flatfile.rb