Class: Marvin::LoggingHandler

Inherits:
CommandHandler show all
Defined in:
lib/marvin/logging_handler.rb

Overview

A generic class to make it easy to implement loggers in marvin. Users only need to implement 1 method for simple logging but have control to do more. Please note that if you want it correctly log the order of messages, it needs to be the first registered handler, otherwise outgoing messages will be processed before incoming ones.

Instance Attribute Summary

Attributes inherited from Base

#client, #from, #options, #target

Instance Method Summary collapse

Methods inherited from CommandHandler

#check_for_commands, command, desc, exposed_methods, #exposed_name, exposed_name, exposes, #extract_command_name, method_added, prefix_is, prefix_regexp, reloading!

Methods inherited from Base

#_handle, #action, #addressed?, #ctcp, event_handlers_for, #from_channel?, #from_user?, #handle, #handle_incoming_numeric, #msg, on_event, on_numeric, #pm, register!, #registered=, registered=, registered?, reloaded!, reloading!, #reply

Instance Method Details

#log_incoming(server, nick, target, message) ⇒ Object

Log an incoming message (i.e. from another user) Note that server is in the port host:port, nick is the origin nick and target is either a channel or the bots nick (if PM’ed)



63
64
# File 'lib/marvin/logging_handler.rb', line 63

def log_incoming(server, nick, target, message)
end

#log_message(server, nick, target, message) ⇒ Object

Logs a message - used when you want to log both incoming and outgoing messages



75
76
# File 'lib/marvin/logging_handler.rb', line 75

def log_message(server, nick, target, message)
end

#log_outgoing(server, nick, target, message) ⇒ Object

Log an outgoing message (i.e. from this user) Note that server is in the port host:port, nick is the bots nick and target is either a channel or the user the bot is replying to.



70
71
# File 'lib/marvin/logging_handler.rb', line 70

def log_outgoing(server, nick, target, message)
end

#presetup_loggingObject



36
37
38
39
# File 'lib/marvin/logging_handler.rb', line 36

def presetup_logging
  @server = self.client.host_with_port
  @nick   = self.client.nickname
end

#setup_loggingObject

Called when the client connects, over ride it to do any of your specific setup.



43
44
45
# File 'lib/marvin/logging_handler.rb', line 43

def setup_logging
  # NOP
end

#should_log?Boolean

Called before logging a message for conditional logging. Override with your implementation specific version.

Returns:

  • (Boolean)


55
56
57
# File 'lib/marvin/logging_handler.rb', line 55

def should_log?
  true
end

#teardown_loggingObject

Called when the client disconnects, over ride it to do any of your specific teardown.



49
50
51
# File 'lib/marvin/logging_handler.rb', line 49

def teardown_logging
  # NOP
end