# SlackLogDevice LogDevice implementation that post logs on a Slack channel. ## Setup Just add this into your `Gemfile`: ```ruby gem 'slack_log_device' ``` Then, just run a `bundle install`. ## Usage ```ruby require 'slack_log_device' logger = Logger.new(SlackLogDevice.new(webhook_url: 'https://hooks.slack.com/services/...', username: 'MyApp')) logger.level = Logger::INFO logger.warn('BAM!') ``` Then, the logged message will be writen to webhook's configured channel. Note that the messages written are buffered in order to avoid consecutive request. ## Options - `auto_flush`: To flush messages directly when a message is written (disabled by default). - `channel`: The channel to post message on (webhook configured channel by default). It can be a channel (if starting with `#`) or a specific user (if starting with a `@`). - `flush_delay`: The delay in seconds to send buffered messages (1 by default). - `max_buffer_size`: The max buffer size to flush messages (8192 by default). - `timeout`: The timeout in seconds to send message to slack (5 by default). - `username`: The username to post message as (nil by default). - `webhook_url`: The URL of the webhook (mandatory). ## Formatter `slack_log_device` provides a log formatter to have a pretty output for slack. It can be configured like this: ```ruby logger.formatter = SlackLogDevice.formatter ``` `SlackLogDevice.formatter` method also accepts block to transform logged message, example: ```ruby logger.formatter = SlackLogDevice.formatter { |message| message.reverse } ``` ## Rails configuration For a rails application, it is recommanded to use following configuration into `config/environments/production.rb` file: ```ruby config.logger = ActiveSupport::Logger.new(SlackLogDevice.new(webhook_url: 'https://hooks.slack.com/services/...', username: 'MyRailsApp')) config.logger.formatter = SlackLogDevice::FORMATTER config.log_level = :warn ``` ## Executing test suite This project is fully tested with [Rspec 3](http://github.com/rspec/rspec). Just run `bundle exec rake` (after a `bundle install`).