2005-06-04 08:15:10 +00:00
|
|
|
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
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Creates a flatfile log sink instance that will be configured to log to
|
|
|
|
# the supplied file path.
|
|
|
|
#
|
2005-06-04 08:15:10 +00:00
|
|
|
def initialize(file)
|
|
|
|
self.fd = File.new(file, "a")
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
def cleanup # :nodoc:
|
2005-06-04 08:15:10 +00:00
|
|
|
fd.close
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
def log(sev, src, level, msg, from) # :nodoc:
|
2005-06-04 08:15:10 +00:00
|
|
|
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'
|
2005-11-09 03:28:21 +00:00
|
|
|
when LOG_WARN
|
|
|
|
code = 'w'
|
2005-06-04 08:15:10 +00:00
|
|
|
end
|
|
|
|
fd.write("[#{get_current_timestamp}] [#{code}(#{level})] #{src}: #{msg}\n")
|
|
|
|
end
|
2005-09-25 19:42:29 +00:00
|
|
|
|
|
|
|
fd.flush
|
2005-06-04 08:15:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
attr_accessor :fd # :nodoc:
|
2005-06-04 08:15:10 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end end end
|