Class: Balotelli::Core::IrcLogger
- Defined in:
- lib/balotelli/core/irc_logger.rb
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- LOG_FORMAT =
proc do |_severity, datetime, _progname, msg| "#{datetime.utc}: #{msg}\n" end
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#channels_logs ⇒ Object
readonly
Returns the value of attribute channels_logs.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
Instance Method Summary collapse
- #channel_log(channel, to_log) ⇒ Object
- #define_log_method ⇒ Object
- #included(des) ⇒ Object
-
#initialize(dir = '', log_name = 'logs.log', channels = []) ⇒ IrcLogger
constructor
A new instance of IrcLogger.
Constructor Details
#initialize(dir = '', log_name = 'logs.log', channels = []) ⇒ IrcLogger
Returns a new instance of IrcLogger.
13 14 15 16 17 18 19 20 21 |
# File 'lib/balotelli/core/irc_logger.rb', line 13 def initialize(dir = '', log_name = 'logs.log', channels = []) @dir = dir check_dir @log_file = new_logger(log_name) @channels = Set.new channels @channels_logs = @channels.each_with_object({}) do |c, o| o[c] = new_logger(channel_log_file(c)) end end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
11 12 13 |
# File 'lib/balotelli/core/irc_logger.rb', line 11 def channels @channels end |
#channels_logs ⇒ Object (readonly)
Returns the value of attribute channels_logs.
11 12 13 |
# File 'lib/balotelli/core/irc_logger.rb', line 11 def channels_logs @channels_logs end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
11 12 13 |
# File 'lib/balotelli/core/irc_logger.rb', line 11 def dir @dir end |
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
11 12 13 |
# File 'lib/balotelli/core/irc_logger.rb', line 11 def log_file @log_file end |
Instance Method Details
#channel_log(channel, to_log) ⇒ Object
41 42 43 44 45 |
# File 'lib/balotelli/core/irc_logger.rb', line 41 def channel_log(channel, to_log) if (logger = @channels_logs[channel]) logger.info to_log end end |
#define_log_method ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/balotelli/core/irc_logger.rb', line 69 def define_log_method define_method :log_file do |str| class_variable_get(:@log_file) end define_method :log do |str| log_string = "LOG: #{str.inspect}\n" log_file.info log_string puts log_string end end |
#included(des) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/balotelli/core/irc_logger.rb', line 23 def included(des) super des.instance_variable_set(:@log_file, log_file) des.instance_variable_set(:@logger, self) define_log_method class << des alias_method :orig_sputs, :sputs private :orig_sputs alias_method :orig_sgets, :sgets private :orig_sgets end des.extend(Methods) end |