global.escape?

A

aidy

Hi,

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

<SNIP>
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
</SNIP>

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,110
Latest member
OdetteGabb
Top