lautis / sweet_notifications

Syntactic sugar for ActiveSupport::LogSubscribers
MIT License
3 stars 1 forks source link

Cannot subscribe in a rails app initializer #1

Open PikachuEXE opened 7 years ago

PikachuEXE commented 7 years ago

I am using redis-rails-instrumentation and I love it. Thanks for developing first! I want to track some custom runtime too, so I created an initializer but nothing happens.

I test with ActiveSupport::Notifications.instrument('read_fragment.cells', key: "test") If I paste this code into rails console than it works (see debug level logging)

Can you help me found out the reasons?

My initializer

# frozen_string_literal: true

require "action_controller"
require "active_support"
require "sweet_notifications"

module Cells
  module Rails
    module Instrumentation
      Railtie, LogSubscriber = SweetNotifications.subscribe(
        :cells,
        label: "Cells",
      ) do
        color(
          ::ActiveSupport::LogSubscriber::CYAN,
          ::ActiveSupport::LogSubscriber::MAGENTA,
        )

        event :read_fragment, runtime: true do |event|
          next unless logger.debug?
          key = event.payload[:key]

          debug(
            message(event, "Cells", "read_fragment: #{key}"),
          )
        end

        event :write_fragment, runtime: true do |event|
          next unless logger.debug?
          key = event.payload[:key]

          debug(
            message(event, "Cells", "write_fragment: #{key}"),
          )
        end
      end
    end
  end
end
PikachuEXE commented 7 years ago

Anyone~?

PikachuEXE commented 6 years ago

Hello~?