2005-06-04 08:15:10 +00:00
|
|
|
module Rex
|
|
|
|
module Logging
|
|
|
|
module Sinks
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Flatfile
|
|
|
|
# --------
|
|
|
|
#
|
|
|
|
# This class implements the LogSink interface and backs it against a
|
|
|
|
# file on disk.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Flatfile
|
|
|
|
|
|
|
|
include Rex::Logging::LogSink
|
|
|
|
|
|
|
|
def initialize(file)
|
|
|
|
self.fd = File.new(file, "a")
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
fd.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def log(sev, src, level, msg, from)
|
|
|
|
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'
|
|
|
|
end
|
|
|
|
fd.write("[#{get_current_timestamp}] [#{code}(#{level})] #{src}: #{msg}\n")
|
2005-09-23 05:51:09 +00:00
|
|
|
fd.flush
|
2005-06-04 08:15:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_accessor :fd
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end end end
|