Class: Balotelli::Core::IrcLogger
- Defined in:
- lib/balotelli/core/irc_logger.rb
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
- #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
60 61 62 63 64 |
# File 'lib/balotelli/core/irc_logger.rb', line 60 def channel_log(channel, to_log) if (logger = @channels_logs[channel]) logger.info to_log end end |
#included(des) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/balotelli/core/irc_logger.rb', line 23 def included(des) super define_log_method des.instance_variable_set(:@log_file, log_file) des.instance_variable_set(:@logger, self) class << des alias_method :orig_sputs, :sputs private :orig_sputs def sputs(str) orig_sputs(str) to_log = ">>#{str.inspect}\n" @log_file.info(to_log) if str =~ /\A:?\S+ (#\S+) .*/ @logger.channel_log($1.downcase, to_log) end str end alias_method :orig_sgets, :sgets private :orig_sgets def sgets str = orig_sgets to_log = "<<#{str.inspect}\n" @log_file.info(to_log) if str =~ /\A:?\S+ \S+ (#\S+) .*/ @logger.channel_log($1.downcase, to_log) end str end end end |