I'm working on a project that has about a bazillion little classes and methods. I was looking for a way to capture the output from $SYSTEM.OBJ.Dump last night and found an old thread on the InterSystems form that involved capturing output from another class that just did "write". It involved using .ReDirect(). Unfortunately, that caused my project to abort in weird spots. I did find a workaround using MVBasic that does the trick nicely without causing exceptions Thought I'd share. The first few methods are pretty-much old hat to anyone who has worked with Cache/Ensemble for a while. The last method, captureObjDump() is "for the money".
--Bill
Method debugDump(thing) As %Stream.TmpCharacter [ Language = cache ]
{
set output = ##class(%Stream.TmpCharacter).%New()
do output.WriteLine( "<pre>")
set level = $STACK(-1) - 1
do output.CopyFrom(..debugSay( "Debug dump from "_$STACK(level)_": "_$STACK(level,"PLACE")_" - "_$STACK(level,"MCODE")))
set ctr = 0
FOR loop= level-1:-1:0 {
do output.WriteLine( "Level "_loop_", context "_$STACK(loop)_": "_$STACK(loop,"PLACE")_ ", line: "_$STACK(loop,"MCODE"))
set ctr = ctr + 1
quit:ctr>4
}
set ze = $ZE
do:ze'["<UNDEFINED" output.WriteLine("System Error: "_ze)
set errorLine = ##class(%SYSTEM.Process).ErrorLine()
do:errorLine'["/source" output.WriteLine( "Error line: "_errorLine)
if $isObject(thing) {
set oRef = $get(thing)
do output.WriteLine( "OREF "_oRef)
do output.CopyFrom(..captureObjDump(oRef))
if (oRef["Core.Array")!(oRef["Core.HashArray") {
set key = thing.Next()
while key '= "" {
set item = thing.get(key)
do output.WriteLine( "Key: "_key)
if $isObject(item) {
do output.CopyFrom(..captureObjDump(item))
} else {
do output.WriteLine( ##class(EasyCSP.Conversions.HexDump).run(item))
}
set key = thing.Next(key)
}
}
} else {
do output.WriteLine( ##class(EasyCSP.Conversions.HexDump).run(thing))
}
do output.WriteLine("</pre>")
do output.Rewind()
quit output
}
Method debugMark(phrase As %String = "") As %Stream.TmpCharacter [ Language = cache ]
{
set output = ##class(%Stream.TmpCharacter).%New()
do output.WriteLine( "<pre>")
set level = $STACK(-1) - 1
do output.CopyFrom(..debugSay(phrase_..crlf_ "Debug dump from "_$STACK(level)_": "_$STACK(level,"PLACE")_" - "_$STACK(level,"MCODE")))
do output.WriteLine("</pre>")
quit output
}
Method debugSay(phrase As %String = "") As %Stream.TmpCharacter [ Language = cache ]
{
set output = ##class(%Stream.TmpCharacter).%New()
do output.WriteLine( "<pre>")
do output.WriteLine(..crlf_..crlf_"===========================================================================================")
do output.WriteLine("==========================================================================================="_..crlf_..crlf)
do output.WriteLine(phrase)
do output.WriteLine(..crlf_..crlf_"===========================================================================================")
do output.WriteLine("==========================================================================================="_..crlf_..crlf)
do output.WriteLine("</pre>")
do output.Rewind()
quit output
}
Method captureObjDump(obj) As %Stream.TmpCharacter [ Language = mvbasic ]
{
output = "%Stream.TmpCharacter"->%New()
output->WriteLine( "<pre>")
%dumpthisthing = obj
execute "[do $SYSTEM.OBJ.Dump(%dumpthisthing)" capturing reply
output->Write(reply)
output->WriteLine( "</pre>")
output->Rewind()
$kill %dumpthisthing
return output
}