module Bones::RPC::Loggable
Contains behaviour for logging.
@since 0.0.1
Public Class Methods
Log the payload to debug.
@example Log to debug.
Loggable.debug("BONES-RPC", payload "30.012ms")
@param [ String ] prefix The log prefix. @param [ String ] payload The log operations. @param [ String ] runtime The runtime in formatted ms.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 42 def self.debug(prefix, payload, runtime) Bones::RPC.logger.debug([ prefix, payload, "runtime: #{runtime}" ].join(' ')) end
Log the provided operations.
@example Log the operations.
Loggable.log_operations("BONES-RPC", {}, 30)
@param [ String ] prefix The prefix for all operations in the log. @param [ Array ] ops The operations. @param [ String ] runtime The runtime in formatted ms.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 20 def self.log_operations(prefix, ops, runtime) indent = " "*prefix.length if ops.length == 1 Bones::RPC.logger.debug([ prefix, ops.first.log_inspect, "runtime: #{runtime}" ].join(' ')) else first, *middle, last = ops Bones::RPC.logger.debug([ prefix, first.log_inspect ].join(' ')) middle.each { |m| Bones::RPC.logger.debug([ indent, m.log_inspect ].join(' ')) } Bones::RPC.logger.debug([ indent, last.log_inspect, "runtime: #{runtime}" ].join(' ')) end end
Log the payload to warn.
@example Log to warn.
Loggable.warn("BONES-RPC", payload "30.012ms")
@param [ String ] prefix The log prefix. @param [ String ] payload The log operations. @param [ String ] runtime The runtime in formatted ms.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 56 def self.warn(prefix, payload, runtime) Bones::RPC.logger.warn([ prefix, payload, "runtime: #{runtime}" ].join(' ')) end
Public Instance Methods
Get the default logger.
@example Get the default logger.
Loggable.default_logger
@return [ Logger ] The default logger.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 93 def default_logger logger = Logger.new(STDOUT) logger.level = Logger::INFO logger end
Get the logger.
@example Get the logger.
Loggable.logger
@return [ Logger ] The logger.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 68 def logger return @logger if defined?(@logger) @logger = rails_logger || default_logger end
Set the logger.
@example Set the logger.
Loggable.logger = logger
@return [ Logger ] The logger.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 107 def logger=(logger) @logger = logger end
Get the rails logger.
@example Get the rails logger.
Loggable.rails_logger
@return [ Logger ] The Rails logger.
@since 0.0.1
# File lib/bones/rpc/loggable.rb, line 81 def rails_logger defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger end