CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/logging/log_sink_factory.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
4
module Rex
5
module Logging
6
7
###
8
#
9
# LogSinkFactory can instantiate a LogSink based on the given name.
10
#
11
###
12
module LogSinkFactory
13
# Creates a new log sink of the given name. If no name is provided, a default
14
# Flatfile log sink is chosen
15
#
16
# @param [String] name The name of the required log sink within Rex::Logging::Sinks
17
# @param [Array] attrs The attributes to use with the given log sink
18
# @return [Rex::Logging::LogSink] The newly created log sink
19
def self.new(name = nil, *attrs)
20
name ||= Rex::Logging::Sinks::Flatfile.name.demodulize
21
raise NameError unless available_sinks.include?(name.to_sym)
22
23
log_sink = Rex::Logging::Sinks.const_get(name)
24
log_sink.new(*attrs)
25
rescue NameError
26
raise Rex::ArgumentError, "Could not find logger #{name}, expected one of #{available_sinks.join(', ')}"
27
end
28
29
# Returns a list of the available sinks that can be created by this factory
30
#
31
# @return [Array<Sym>] The available sinks that can be created by this factory
32
def self.available_sinks
33
Rex::Logging::Sinks.constants - [Rex::Logging::Sinks::Stream.name.demodulize.to_sym]
34
end
35
end
36
end
37
end
38
39