Sha256: ac6a54a308a5151501d6d06d76fd602cc9272112530102fedabb4be4254458ad
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
# 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 ``` ## 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 = ::Logger::Formatter.new 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`).
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slack_log_device-2.2.0 | README.mdown |