Permalink
Browse files

add a logging module

  • Loading branch information...
1 parent ad0fdd2 commit 02ce637d5dddfaaa4e1241d62b80b3ffd297ce6f @jamesgolick committed Apr 30, 2009
Showing with 32 additions and 0 deletions.
  1. +2 −0 lib/trample.rb
  2. +14 −0 lib/trample/logging.rb
  3. +16 −0 test/logging_test.rb
View
@@ -1,3 +1,4 @@
+require 'log4r'
require 'rest_client'
module Trample
@@ -6,6 +7,7 @@ module Trample
autoload :Session, File.dirname(__FILE__) + "/trample/session"
autoload :Runner, File.dirname(__FILE__) + "/trample/runner"
autoload :Cli, File.dirname(__FILE__) + "/trample/cli"
+ autoload :Logging, File.dirname(__FILE__) + "/trample/logging"
class << self
attr_reader :current_configuration
@@ -0,0 +1,14 @@
+module Trample
+ module Logging
+ def logger
+ init_logger if Log4r::Logger['main'].nil?
+ Log4r::Logger['main']
+ end
+
+ protected
+ def init_logger
+ logger = Log4r::Logger.new('main')
+ logger.outputters = Log4r::Outputter.stdout
+ end
+ end
+end
View
@@ -0,0 +1,16 @@
+require 'test_helper'
+
+class LoggingTest < Test::Unit::TestCase
+ context "The logging module" do
+ setup do
+ @object = Class.new do
+ include Trample::Logging
+ end.new
+ @object.send(:init_logger)
+ end
+
+ should "return Log4r::Logger['main'] for #logger" do
+ assert_equal Log4r::Logger['main'], @object.logger
+ end
+ end
+end

0 comments on commit 02ce637

Please sign in to comment.