Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid evaluating code in debug logs #291

Merged
merged 1 commit into from
Jan 7, 2015
Merged
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
12 changes: 8 additions & 4 deletions lib/listen/adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ def _queue_change(type, dir, rel_path, options)
@mq.send(:_queue_raw_change, type, dir, rel_path, options)
end

def _log(*args)
self.class.send(:_log, *args)
def _log(*args, &block)
self.class.send(:_log, *args, &block)
end

def _log_exception(msg)
_log :error, format(msg, $ERROR_INFO, $ERROR_POSITION * "\n")
end

def self._log(*args)
Celluloid::Logger.send(*args)
def self._log(*args, &block)
if block
Celluloid::Logger.send(*args, block.call)
else
Celluloid::Logger.send(*args)
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/listen/adapter/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def handle_data(data)
# Handles incoming message by notifying of path changes
def handle_message(message)
type, change, dir, path, _ = message.object
_log :debug, "TCP message: #{[type, change, dir, path].inspect}"
_log(:debug) { "TCP message: #{[type, change, dir, path].inspect}" }

_queue_change(type.to_sym, Pathname(dir), path, change: change.to_sym)
end

Expand Down
20 changes: 12 additions & 8 deletions lib/listen/internals/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
module Listen
module Internals
module Logging
def _info(*args)
_log(:info, *args)
def _info(*args, &block)
_log(:info, *args, &block)
end

def _warn(*args)
_log(:warn, *args)
def _warn(*args, &block)
_log(:warn, *args, &block)
end

def _debug(*args)
_log(:debug, *args)
def _debug(*args, &block)
_log(:debug, *args, &block)
end

def _log(*args)
Celluloid::Logger.send(*args)
def _log(*args, &block)
if block
Celluloid::Logger.send(*args, block.call)
else
Celluloid::Logger.send(*args)
end
end

def _format_error(fmt)
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _stop_wait_thread
end

def _queue_raw_change(type, dir, rel_path, options)
_debug "raw queue: #{[type, dir, rel_path, options].inspect}"
_debug { "raw queue: #{[type, dir, rel_path, options].inspect}" }

unless (worker = async(:change_pool))
_warn 'Failed to allocate worker from change pool'
Expand Down