Path: blob/master/lib/rex/logging/sinks/stream.rb
19566 views
# -*- coding: binary -*-123module Rex4module Logging5module Sinks67###8#9# This class implements the LogSink interface and backs it against a stream10###11class Stream1213include Rex::Logging::LogSink1415def initialize(stream)16@stream = stream17end1819#20# Writes log data to a stream21#22def log(sev, src, level, msg) # :nodoc:23if sev == LOG_RAW24stream.write(msg)25else26stream.write("[#{get_current_timestamp}] [#{log_code_for(sev)}(#{level})] #{src}: #{msg}\n")27end2829stream.flush30end3132def cleanup # :nodoc:33stream.close34end3536protected3738attr_accessor :stream # :nodoc:3940#41# This method returns the corresponding log code for the given severity42#43def log_code_for(sev)44code = 'i'4546case sev47when LOG_DEBUG48code = 'd'49when LOG_ERROR50code = 'e'51when LOG_INFO52code = 'i'53when LOG_WARN54code = 'w'55end5657code58end5960end6162end end end636465