Class: Rex::Logging::Sinks::Flatfile

Inherits:
Object
  • Object
show all
Includes:
LogSink
Defined in:
lib/rex/logging/sinks/flatfile.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Flatfile

Creates a flatfile log sink instance that will be configured to log to the supplied file path.



20
21
22
# File 'lib/rex/logging/sinks/flatfile.rb', line 20

def initialize(file)
  self.fd = File.new(file, "a")
end

Instance Method Details

#cleanupObject

:nodoc:



24
25
26
# File 'lib/rex/logging/sinks/flatfile.rb', line 24

def cleanup # :nodoc:
  fd.close
end

#log(sev, src, level, msg, from) ⇒ Object

:nodoc:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rex/logging/sinks/flatfile.rb', line 28

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