Logging info to a file across multiple p files?

freak

Member
Logging info to a text file across multiple p files?

Using 9.1d... I have a p file which calls maybe 6-8 other p files which may also call a few others. What are some good ways to allow them all to write to a common text log file? I thought about passing the log file name to all the p files but I sure there are better ways. Any ideas?
 

TomBascom

Curmudgeon
Re: Logging info to a text file across multiple p files?

Even 9.1D, ancient, obsolete and unsupported though it may be, supports OUTOUT TO. So, basically, in the controlling program you would say OUTPUT TO value( logFile ).

If this program also has output to the screen then you might want to get fancy and declare a named stream:

/* prog1.p */

define new global shared stream logStream.
output stream logStream to value( "logFile" ).

put stream logStream "some message" skip.
...
run prog2.p.
...
run progr3.p.
...
output stream logStream close.

/* prog2.p */

define new global shared stream logStream.
/* no need to have an "output to" here... */
put stream logStream "another message" skip.
return.

Or, if you want to get really fancy, you could isolate the logging function in a common library routine that manages the log file and use PUBLISH & SUBSCRIBE to communicate the messages.
 

freak

Member
Re: Logging info to a text file across multiple p files?

Yes I know how to use OUTPUT TO. I just wasn't sure that passing the log file name as a parameter was the best way to do it.

BTW - I'm going to upgrade Progress as soon as I find a routine to convert 100's of rb reports to Crystal.
 

tamhas

ProgressTalk.com Sponsor
Re: Logging info to a text file across multiple p files?

Or, if you want to get really fancy, you could isolate the logging function in a common library routine that manages the log file and use PUBLISH & SUBSCRIBE to communicate the messages.

This is actually a far better way to go than to weave an output stream though everything. Take a look at http://www.oehive.org/ExceptionClass ... it is OO code, so you can't use it yet as is, but the basic idea is easily implemented with a super procedure. The SP can either just print to the log directly ... very simple ... or, like my example, it can save up the messages for you and let you decide what to do with them at the end.

I don't know anything about RB, but I thought there was still a run-time available on new versions. If so, you could move and then convert to Crystal at your leisure.
 

freak

Member
Re: Logging info to a text file across multiple p files?

I played with publish and subscribe a bit but it seems (unless I'm doing something wrong) that it can only go one level down the call stack. If I have a window that I want to send a message to from a prog that is 2 or 3 levels deep it appears that it cannot be done. Am I missing something?
 

freak

Member
Re: Logging info to a text file across multiple p files?

Looks like if I pass the handle from the main calling program down the stack I can make it work. Is that a generally acceptable way to do it?
 

TomBascom

Curmudgeon
Re: Logging info to a text file across multiple p files?

No. I don't know what you are doing but whatever it is it is all wrong. There is no need to be passing a handle -- one of the great advantages of PUB/SUB is to be able to do away with all of that garbage.

Code:
/* main.p
 */

run superlib.p persistent.

run prog1.p

/* prog1.p
 */

publish logMsg ( "hello world" ).

run prog2.p

return.

/* prog2.p
 */

publish logMsg ("goodbye cruel world!" ).

return.

/* superlib.p
 */

procedure messageLogger:

  define input parameter msgText as character no-undo.

  output to value( "logfile" ) append.
  put unformatted today " " now " " msgText skip.
  output close.

  return.

end.

session:add-super-procedure( this-procedure ).

subscribe to "logMsg" anywhere run-procedure "messageLogger".

return.
 

freak

Member
Re: Logging info to a text file across multiple p files?

I was trying to pass the messages not only to a log file but also back up to the main calling program (which in this case is a window) so they can be displayed in a control. This allows me to get messages without action stopping popups and display them during execution. So while in you example I can call logmsg from anywhere, I do not see how main.p can "have" the messages.
 

tamhas

ProgressTalk.com Sponsor
Re: Logging info to a text file across multiple p files?

This is exactly what my exception handling classes do. You could easily convert them to a superprocedure and decide either to add real time logging to a file or do as I do, which is to empty the message stack at key points.
 

freak

Member
Re: Logging info to a text file across multiple p files?

Yes I downloaded that. I haven't had time to digest it yet.
 

TomBascom

Curmudgeon
Re: Logging info to a text file across multiple p files?

I was trying to pass the messages not only to a log file but also back up to the main calling program (which in this case is a window) so they can be displayed in a control. This allows me to get messages without action stopping popups and display them during execution. So while in you example I can call logmsg from anywhere, I do not see how main.p can "have" the messages.

This is a long way away from your original problem description...

In any event (so to speak...) there is no limit on the number of subscribers. Subscribe to logMsg in main.p and do whatever you'd like with the message.
 

freak

Member
Re: Logging info to a text file across multiple p files?

Ok... I played with it for a while. I understand it now. Thank you Tom and Thomas for all your help!
 
Top