Bamm Log
Who doen't need to log what's going on in your Modular Sinatra App? Well.. I need. By default sinatra logs this:
127.0.0.1 - - [25/Aug/2014 17:23:11] "GET /page HTTP/1.1" 200 6736 2.5322
127.0.0.1 - - [25/Aug/2014 17:24:33] "POST /create HTTP/1.1" 200 5833 0.0198
/create with which params?
127.0.0.1 - - [25/Aug/2014 17:24:33] "POST /error HTTP/1.1" 500 5443 0.1238
This page returns 500 for what? You can check our apage error.log file or you can log everything in one file, like Rails!
After reading some implementations, I joined some ideas and created this gem. It's not tested yet, so.. don't use it on production.
[2014-08-25 16:03:43 +0000] Started GET "/page?page=1&per_page=99"
[2014-08-25 16:03:43 +0000] Parameters: "per_page"=>"99"[2014-08-25 17:36:59 +0000] Started POST "/create"
[2014-08-25 17:36:59 +0000] Parameters: "title" => "Nice and Clean" }[2014-08-25 17:36:59 +0100] Started GET "/v0/page?page=1&per_page=99"
[2014-08-25 17:36:59 +0100] Parameters: "per_page"=>"99"
[2014-08-25 17:37:05 +0100] Bamm! RuntimeError: bamm error
[2014-08-25 17:37:05 +0100] /app/routes/page.rb:4:in `block in class:App'extended backtrace...
Installation
Add this line to your application's Gemfile:
gem 'bamm_log'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bamm_log
Usage
class RequisitionsService < Sinatra::Base
configure :staging do
include BammLog::Logger
end
# if you want to user logger in your application,
# being logged to the same "environment".log file
def logger
BammLog.logger
end
end
This will create a file with the name "environment".log (ex: staging.log) and log all the accesses and errors from you application.
Contributing
- Fork it ( http://github.com/joaquimadraz/bamm_log/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request