Commit 5acd865
Changed files (3)
spec
unit
lib/nasty/log.rb
@@ -0,0 +1,27 @@
+require "logger"
+
+module Nasty
+ class Log
+ class << self
+ def bind_to(log_factory)
+ @@log_factory = log_factory
+ end
+
+ def for(target)
+ @@log_factory || ConsoleLogFactory.new
+ @@log_factory.create_for(target)
+ end
+ end
+ end
+
+ class ConsoleLogFactory
+ def initialize(logger = Logger.new(STDOUT), level = Logger::DEBUG)
+ @logger = logger
+ @logger.level = level
+ end
+
+ def create_for(target)
+ @logger
+ end
+ end
+end
lib/nasty.rb
@@ -2,6 +2,7 @@ require "nasty/background_job"
require "nasty/command"
require "nasty/composite_command"
require "nasty/kernel"
+require "nasty/log"
require "nasty/lambda_behaviours"
require "nasty/version"
spec/unit/log_spec.rb
@@ -0,0 +1,32 @@
+require "spec_helper"
+
+describe Logger do
+ context "playtime" do
+ it "should log stuff" do
+ logger = Logger.new(STDOUT)
+ logger.level = Logger::DEBUG
+
+ #logger.debug("i am logged")
+ #logger.close
+ end
+ end
+end
+
+module Nasty
+ describe Log do
+ context "when logging stuff" do
+ let(:logger) { double("", debug: true) }
+ let(:log_factory) { double }
+
+ before :each do
+ log_factory.stub(:create_for).with(self).and_return(logger)
+ Log.bind_to(log_factory)
+ Log.for(self).debug("hi there")
+ end
+
+ it "should log to the bound logger" do
+ logger.should have_received(:debug).with("hi there")
+ end
+ end
+ end
+end