Files
metasploit-gs/lib/rex/logging/sinks/flatfile.rb
T
Brent Cook ca5bc94ccf kill never unused 'from' argument in library logs
This avoids computing a stack trace on every single log message
that is never used in any of the logging sinks. This is one of the
number one profiled memory allocation/deallocation events in Metasploit
as shown with memory_profiler.
2019-12-02 09:03:58 -06:00

57 lines
912 B
Ruby

# -*- 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) # :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