ca5bc94ccf
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.
23 lines
460 B
Ruby
23 lines
460 B
Ruby
# -*- coding: binary -*-
|
|
module Rex
|
|
module Logging
|
|
module Sinks
|
|
|
|
###
|
|
#
|
|
# This class implements the LogSink interface and backs it against a
|
|
# file on disk with a Timestamp.
|
|
#
|
|
###
|
|
class TimestampFlatfile < Flatfile
|
|
|
|
def log(sev, src, level, msg) # :nodoc:
|
|
return unless msg.present?
|
|
msg = msg.gsub(/\x1b\[[0-9;]*[mG]/,'').gsub(/[\x01-\x02]/, ' ').gsub(/\s+$/,'')
|
|
fd.write("[#{get_current_timestamp}] #{msg}\n")
|
|
fd.flush
|
|
end
|
|
end
|
|
|
|
end end end
|