LogGobbler; Getting your logs in one place.
Friday, August 22nd, 2008LogGobbler is pretty simple pseudo REST logging service. It’s built on top of merb/datamapper and includes a client for logging activity. LogGobbler allows you to avoid disk I/O and store all of your logs in groups (or application groups) on a remote server.
LogGobbler is pretty quick, it uses merbs ‘run_later’ to just acknowledge the message and put it in a queue to be logged. All the URIs and request objects are cached on the client side so they don’t have to be recreated for each use. In the next release message queuing and a bulk log interface will exist so HTTP sessions don’t have to be created for every message.
All logs are stored via DataMapper (so choose your own storage engine) and are directly related to a ‘Gobbler’ or application for later retrieval and processing.
LogGobbler mimics the standard ruby logger interface, so you can just drop it in, instantiate the gobbler clients and you’re using it! (Oh, and of course start the server somewhere ;))
Here are some examples:
Configure a gobbler client
client_config = {
:gobbler_host => 'localhost',
:gobbler_port => 9090,
:gobbler_use_ssl => false,
:authentication => 'gobbler:p@ssw0rd', #false
:log_level => INFO
}
# Gobblers are grouped by their application names, a description is just needed for humans.
exception_config = client_config.merge({
:description => "Logs all exceptions",
:application => "My2.0App"
})
exception_logger = LogGobbler::Client.new(exception_config)
exception_logger.info "My logger is online!"
exception_logger.info {"It really is, SRSLY"}
#An addition to the ruby standard logger interface is the ability to log exceptions themselves.
exception_logger.exception(Errno::ENOENT, "Oh noez!? an exception")
# or more professionally...
exception_logger.exception(Errno::ENOENT,"#{__FILE__} @ line: #{__LINE__}")
This logger keeps track of user logins (given a User class)
login_logger = LogGobbler::Client.new(client_config.merge({
:description => "Track all logins",
:application => "My2.0App"
}))
user = User.authentication("Somebody","secr3t_passw0rd")
if user.authenticated?
login_logger.info("#{user.name} logged in from #{request.remote_ip}")
# .... your cool app stuff .... #
else
# .... your cool, 'you messed up logging in' stuff .... #
end
Of course, you can just use it for all of your general logging.
Merb.logger = LogGobbler::Client.new(client_config.merge({
:description => "General logging activity",
:application => "My Awesome App!"
}))
Merb.logger.info "My message was stored across the internetz?!"
If you’d like to play with or contribute to the gobbler, join in!
