ElasticLogger
ElasticLogger is a simple and elastic (;)) solusion for sending JSON logs to elasticsearch but not only there. It works based on writers. Each writer is used to send logs to diffrent destination. Gem is released with two writers one for ElasticSearch and one for standard log files. You can also create your own Writer and use it in config file.
Installation
Add this line to your application's Gemfile:
gem 'elastic-logger'
And then execute:
$ bundle
Or install it yourself as:
$ gem install elastic-logger
Usage Examples
There is a generator for Rails which will create base intialize and config files.
bundle exec rails generate elastic_logger
require 'elastic-logger'
ElasticLogger.configure do |config|
config.host = '192.168.60.10:9200'
types_file = 'config/elastic_log_config.yml'
path = 'log'
prefix = ''
end
Config file
With this file we create two logs, one which will log to elastic, and one to standard log file.
sidekiq_monitor:
writer: 'InfaktLogger::ElkWriter'
level: 'debug'
delete:
type: 'standard'
unit: 'days'
unit_count: 2
backup:
type: 'standard'
unit: 'days'
unit_count: 2
api_requests:
writer: 'InfaktLogger::DiskWriter'
level: 'warn'
Usage
sidekiq_monitor
is a name of log it will be used with prefix
to build file name or index name in elastic.
logger = ElasticLogger::Logger.new('sidekiq_monitor')
logger.log(foo: :bar)
Writers
ElastickWriter
Creates daily index named after log name. For sidekiq_monitor it will creates sidekiq_monitr-%Y.%m.%d
index each day, with sidekiq_monitor
type and injects there hashes from user input. Next you can go to Kibana and search in it.
DiskWriter
It is use by us mostly on devels, when we don't want to use elk for logs. Internally it use ruby Logger
.
Custom Writer
You can create your own writer. It needs two mtethods:
initialize
with name
and config
named paramslog
with one params with is hash to log.
Capistrano
require 'elastic-logger/capistrano'
Index in elasticsearch will be updated after deploy, with all used elk logs.
Contributing
- 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