PierConsoleDetective
A gem to track commands typed in rails console along with tagging in realtime. The tags can be used to identify users. This works with IRB and rails console using IRB. The values for tag, logger, and memoization requirements are configurable.
IRB provide options for recording history. It has a few disadvantages:
- It is not possible to get the logs in realtime.
- There are no tagging options available.
- There is no way to know the time when the command was fired.
- If we're connecting to the console using ssh, the logs will be lost if the connection is disconnected since the logs are only written only when we exit the session.
pier_console_detective
overcomes such disadvantages.
Installation
Add this line to your application's Gemfile:
gem 'pier_console_detective'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install pier_console_detective
Usage
There are meaningful defaults for the config. If you are using rails, run rails console
. Otherwise, irb -rpier_console_detective
will load the respective consoles with pier_console_detective
loaded. You can also modify ~/.irbrc
with require pier_console_detective
to load the pier_console_detective
by default.
The configs can be overridden by creating a file named pier_console_detective.rb
with following code.
require 'pier_console_detective'
PierConsoleDetective.setup do |config|
config.logger = Rails.logger
config.log_tag = -> { ENV['USER'] }
config.tag_memoization = true
end
If you are using rails, place this file in config/initializers
folder and run rails console
. Otherwise, irb -r ./pier_console_detective.rb
will load the respective consoles with pier_console_detective
loaded with modified config. You can also modify ~/.irbrc
with require pier_console_detective.rb
to load the modified config by default.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment. bin/console
will run in IRB.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/arunn/pier_console_detective.