Question

OUTPUT TO "logfile.txt".

FOR EACH ...:
  ...
  PUT "Some log data". OUTPUT CLOSE. OUTPUT TO "logfile.txt" APPEND.
  ...
END.

Haven't found an appropriate statement to save file at some point. I don't wanna use UNBUFFERED APPEND because it is supposedly slower. Maybe there is built-in logging tools? Maybe STREAMS could help me? Problem in my solution that I have to specify log filename each time i open it with OUTPUT TO statement. A nested procedure may not have a clue about filename.

Was it helpful?

Solution 2

There is no "save" option.

However... you can force output to be flushed with:

put control null(0).

"Supposedly slower" is awfully vague. Yes, there is potentially more IO with unbuffered output. But whether or not that really matters depends heavily on what you are doing and how it will be used. It is very unlikely that it actually matters.

A STREAM would certainly help to keep things organized and make it so that you don't have to know the name of the file in nested procedures.

Yes, there are built in logging tools. Look at the LOG-MANAGER system handle.

The code in the question would be better written as:

define stream logStream.

output stream logStream to value( "log.txt" ) append unbuffered.

for each customer no-lock:
  put stream logStream custName skip.
  /* put stream logStream control null(0). */  /* if you want to try fooling with buffered output... */
end.

output stream logStream close.

OTHER TIPS

The question as it stands is still ambiguous.

If you want a way to route the output through a standard "service" similar to what LOG-MANAGER does, you can do that by using

  1. static members of a class,
  2. by using an API in a persistent procedure and PUBLISHing to it,
  3. by using an API in a session super-procedure and calling it's API

STREAMS will give you a way to segregate output for a single procedure or class to a single file, and keep that output from getting mingled with the production output, however it's limited to the current program, which means it's not a general solution as an application-wide logging facility.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top