class Rex::Logging::LogDispatcher
The log dispatcher associates log sources with log sinks. A log source is a unique identity that is associated with one and only one log sink. For instance, the framework-core registers the ‘core’
Public Class Methods
Creates the global log dispatcher instance and initializes it for use.
# File lib/rex/logging/log_dispatcher.rb, line 19 def initialize() self.log_sinks = {} self.log_levels = {} self.log_sinks_lock = Mutex.new end
Public Instance Methods
Returns the sink that is associated with the supplied source.
# File lib/rex/logging/log_dispatcher.rb, line 28 def [](src) sink = nil log_sinks_lock.synchronize { sink = log_sinks[src] } return sink end
Calls the source association routie.
# File lib/rex/logging/log_dispatcher.rb, line 41 def []=(src, sink) store(src, sink) end
Removes a source association if one exists.
# File lib/rex/logging/log_dispatcher.rb, line 68 def delete(src) sink = nil log_sinks_lock.synchronize { sink = log_sinks[src] log_sinks.delete(src) } if (sink) sink.cleanup return true end return false end
This method returns the log level threshold of a given source.
# File lib/rex/logging/log_dispatcher.rb, line 109 def get_level(src) log_levels[src] end
Performs the actual log operation against the supplied source
# File lib/rex/logging/log_dispatcher.rb, line 89 def log(sev, src, level, msg, from) log_sinks_lock.synchronize { if ((sink = log_sinks[src])) next if (log_levels[src] and level > log_levels[src]) sink.log(sev, src, level, msg, from) end } end
This method sets the log level threshold for a given source.
# File lib/rex/logging/log_dispatcher.rb, line 102 def set_level(src, level) log_levels[src] = level.to_i end
Associates the supplied source with the supplied sink. If a log level has already been defined for the source, the level argument is ignored. Use set_log_level to alter it.
# File lib/rex/logging/log_dispatcher.rb, line 50 def store(src, sink, level = 0) log_sinks_lock.synchronize { if (log_sinks[src] == nil) log_sinks[src] = sink set_log_level(src, level) if (log_levels[src] == nil) else raise( RuntimeError, "The supplied log source #{src} is already registered.", caller) end } end