Logger for LTSV(Labeled Tab-separated Values) format. See http://ltsv.org/ about LTSV.
Add this line to your application's Gemfile:
gem 'ltsv-logger'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ltsv-logger
Use Hash
instead of String
message:
# e.g.: rails
require 'ltsv-logger'
LTSV::Logger.open(File.join('log', "event_#{Rails.env}.log"))
ltsv = { method: "GET", uri: "/foo", status: 200 }
LTSV.logger.info ltsv # => time:2013-04-02 21:55:05 +0900 method:GET uri:/?max_id=9235&page=2 status:200
If logging Hash
like request parameters, serialize Hash
. e.g.:Hash.to_json
:
# e.g.: rails
# params = { max_id: 9235, page: 2, controller: 'foo', action: 'bar' }
ltsv = { method: "GET", uri: "/?max_id=9235&page=2", status: 200, params: params.to_json }
LTSV.logger.info ltsv # => time:2013-04-02 21:55:05 +0900 method:GET uri:/?max_id=9235&page=2 status:200 params:{"max_id":"9235","page":"2","controller":"foo","action":"bar"}
Maybe, to use Marshal
is not good, because it's difficult to deserialize with other programe launguage.
Other way, you can use String
, as usual:
LTSV.logger.info "This is sample." # => time:2013-04-02 21:55:05 +0900 message:This is sample.
- Fork it
- 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
Copyright © 2013 terut. See LICENSE.txt(MIT-LICENCE) for further details.