Skip to content
This repository has been archived by the owner on Mar 9, 2018. It is now read-only.

Config to set AR logger to Rapns.logger #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/rapns
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ load 'config/initializers/rapns.rb' if File.exist?('config/initializers/rapns.rb

Rapns.config.update(config)
Rapns.require_for_daemon
ActiveRecord::Base.logger = Rapns.logger if Rapns.config.intercept_active_record_logger

Rapns::Daemon.start
3 changes: 3 additions & 0 deletions lib/generators/templates/rapns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Define a custom logger.
# config.logger = MyLogger.new

# Set ActiveRecord logger to Rapns.logger.
# config.intercept_active_record_logger = false

end

Rapns.reflect do |on|
Expand Down
3 changes: 2 additions & 1 deletion lib/rapns/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.configure

CONFIG_ATTRS = [:foreground, :push_poll, :feedback_poll, :embedded,
:airbrake_notify, :check_for_errors, :pid_file, :batch_size,
:push, :store, :logger, :batch_storage_updates]
:push, :store, :logger, :batch_storage_updates, :intercept_active_record_logger]

class ConfigurationWithoutDefaults < Struct.new(*CONFIG_ATTRS)
end
Expand Down Expand Up @@ -80,6 +80,7 @@ def set_defaults
self.store = :active_record
self.logger = nil
self.batch_storage_updates = true
self.intercept_active_record_logger = false

# Internal options.
self.embedded = false
Expand Down
8 changes: 8 additions & 0 deletions lib/rapns/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def warn(msg)
log(:warn, msg, 'WARNING', STDERR)
end

def debug(msg)
log(:debug, msg)
end

def debug?
Rails.configuration.log_level == :debug
end

private

def setup_logger(log)
Expand Down