Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add a logging module

  • Loading branch information...
commit 02ce637d5dddfaaa4e1241d62b80b3ffd297ce6f 1 parent ad0fdd2
@jamesgolick authored
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
2  lib/trample.rb
@@ -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
View
14 lib/trample/logging.rb
@@ -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
16 test/logging_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.