42 lines
1.0 KiB
Ruby
42 lines
1.0 KiB
Ruby
require 'log4r'
|
|
require 'blankslate'
|
|
|
|
module SharpCoin
|
|
# If an object doesn't have a logger, we 'log' to this instead.
|
|
# @author Nick Thomas <nick@lupine.me.uk>
|
|
class DummyLogger < BlankSlate
|
|
def method_missing(*args)
|
|
STDERR.puts("DummyLogger: #{args.inspect}")
|
|
end
|
|
end
|
|
|
|
# Include this in any class where you want logging to go to a single place.
|
|
# Controlled by SharpCoin::Config, obviously.
|
|
# @author Nick Thomas <nick@lupine.me.uk>
|
|
module Logging
|
|
class << self
|
|
def logger
|
|
nil
|
|
end
|
|
end
|
|
|
|
def logger
|
|
@logger || Logging::logger || DummyLogger.new
|
|
end
|
|
|
|
# @param[Array[Symbol,String]|Array[String]] Data to log. Can specify a log
|
|
# level and a message, or just a message. If the latter, then we default
|
|
# to info
|
|
def log(*args)
|
|
case args.size
|
|
when 1 then logger.info(args[0])
|
|
when 2 then logger.send(*args)
|
|
else
|
|
logger.warn("Bad method signature for log. Args: #{args.inspect}")
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
|