Global.escape?

Hi,

I have a logger class wrapped up a module as not to conflict with the
Ruby logger class

module Utilities class Logger require "rexml/document" include REXML

def initialize
@doc = Document.new
xmldecl = XMLDecl.default
@doc.add(xmldecl)
@root = @doc.add_element ‘testresults’
end

def test_case(test_name, test_desc)
@test = @root.add_element ‘test’
@test.attributes[“id”] = test_name
des= @test.add_element ‘description’
des.text = test_desc
end

#cannot have a test result without a test case
def test_results(msg)
if yield
test_status = @test.add_element ‘teststatus’
test_status.text = ‘PASS’
else
fail = @test.add_element ‘teststatus’
fail.text = ‘FAIL’
fail_msg = @test.add_element ‘failmessage’
fail_msg.text = msg
end
end

def write_xml_to_file(file_name=“C:/test_results.xml”)
@doc.write($stdout, 1)
@doc.write(File.open(file_name,“w”))
end
end
end

I use this logger in various classes and modules, and I feel ashamed
by using a global variable

$log = Utilities::Logger.new

I have tried using an attr_reader on @root without success.

Is there anyway I can use this class in my project without using a
global?

Regards

Aidy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs