Where is the Pickle?
Wouldn't it be nice if you could save messages in production to see them later? Things like: “suspicious action”, “this request is taking too long” or “third part service is not working again”.
We use Mongoid as database, so you can save anything that is serializable.
Installation
Add this line to your application's Gemfile:
gem 'pickle-surprise'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pickle-surprise
Usage
This gem is intended to be very simple:
class Customer
include Pickle::Surprise
def suspicious
Pickle msg: "#{@name} is trying something…"
end
end
Pickle from any place in your source code:
include Pickle::Surprise
Pickle msg: "Something is strange"
You can have a block that catches all exceptions, creates a Pickle and reraise them:
Pickle do
raise 'FFFUUUUUU-'
end
Pickle expects 3 fields:
- msg (String): message
- ns (String): namespace
- ts (Time): timestamp
But you can save anything that is serializable in a Pickle:
Pickle msg: 'some crazy exception', stack: [1,2,3]
What if I want to build an interface for my Pickles?
puts "You have #{Pickle.count}"
puts "My last Pickle: #{Pickle.last}"
Pickle.all.each do |pickle|
puts pickle.msg
end
# Forget all my Pickles!
Pickle.reset
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am "Added a new feature"
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- ???
- PROFIT