Sha256: 0833f0a942c17b1512b5d416b62c1efa156bf00b6ea1a3c9d134d44b509f891c

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require "active_support/logger"
require "active_support/core_ext/module/attribute_accessors"

require "net/http"
require "net/https"
require "uri"

require "slack_webhook_logger/logger"
require "slack_webhook_logger/formatter"
require "slack_webhook_logger/request_io"

module SlackWebhookLogger
  # Can be modified in Rails app
  mattr_accessor :webhook_url
  mattr_accessor :level
  mattr_accessor :formatter
  mattr_accessor :ignore_patterns
  mattr_accessor :application_name

  # Used internally
  mattr_reader :webhook_uri
  mattr_reader :logger
  mattr_reader :https

  class << self
    # rubocop:disable Style/ClassVars
    def setup
      @@logger = SlackWebhookLogger::Logger.new(SlackWebhookLogger::RequestIO)

      yield self

      @@logger.formatter = @@formatter || SlackWebhookLogger::Formatter.new
      @@logger.level = @@level || :warn

      begin
        @@webhook_uri = URI.parse(@@webhook_url)
      rescue URI::InvalidURIError
        raise ArgumentError, "Invalid URI for webhook_url"
      end

      @@application_name ||= Rails.application.class.module_parent_name
      @@ignore_patterns ||= []
    end
    # rubocop:enable Style/ClassVars
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
slack_webhook_logger-0.7.0 lib/slack_webhook_logger.rb
slack_webhook_logger-0.6.5 lib/slack_webhook_logger.rb
slack_webhook_logger-0.6.4 lib/slack_webhook_logger.rb
slack_webhook_logger-0.6.3 lib/slack_webhook_logger.rb
slack_webhook_logger-0.6.2 lib/slack_webhook_logger.rb
slack_webhook_logger-0.6.1 lib/slack_webhook_logger.rb
slack_webhook_logger-0.6.0 lib/slack_webhook_logger.rb