Debug logging on the Appserver

Posted by Patrick Tingen on 19-Apr-2016 04:35

For our application we use a session-persistent procedure that listens to the event 'DEBUG-MESSAGE'. Whenever it receives such a message, it finds out which program sent it and which user started the program. It then uses the LOG-MANAGER to create or re-use a logfile, specific for that user, program and date.. A typical name for a logfile could be

psspecmt1_20160419_nljrbkl.log

Where psspecmt1 is the program and nljrbkl is the user. The mechanism can be controlled via a general setting in our database so we can turn it on or off as we like and set the folder the logfile needs to be written to. This mechanism also holds a maximum lifetime for the logfiles so they get cleaned up automatically after some days. 

So far, so good. 

The problem arises on the AppServer. We use the same mechanism for procedures that run there. But since we cannot set the name of the logfile in the LOG-MANAGER (see PKB 000037132), all of our debug messages end up in the Appserver logfile. 

That itself is not the biggest issue, but the AppServer logfiles grow rapidly, the developers have no access to these logfiles and the contents of the logfile is now mixed with both connect / disconnect info, which is not interesting for the developers, and application debug info, which is not interesting for our admins. 

In the past we have used a persisitent procedure that did a normal "OUTPUT TO" and closed itself, but it gave us too much headache; when procedures ended prematurely, the file remained locked or on consecutive runs, the log mechanism itself crashed because it tried to write to a locked file. 

So my question is: what would be a good alternative? (10.2B)

Posted by GregHiggins on 19-Apr-2016 14:58

And in that case I would use a doeul block.

do on error undo, leave on stop undo, leave on quit undo, leave:

 output [stream] ...

 ...

end.

catch e as Error:

 /* log error */

end /* catch e */.

finally:

  output [stream] ... close.

end finally.

/* checked my notes, should be leave here.  on error can be undo, leave or undo, throw  which you would use depends */

All Replies

Posted by GregHiggins on 19-Apr-2016 05:03

Does 10.2B have the finally block? I think all of 10 does, but I could be wrong, Whenever I use a an output to .... I put an output [stream ... ]  close in the finally block of the procedure or method that is responsible. If it is not available make sure you write to a stream and then close the stream before you do the output. This last "trick" should work for all pre V10 versions back to V5.

Posted by bronco on 19-Apr-2016 05:29

Have you considered "forcing" a close of the open files via the AppServer deactivate procedure? I would create a class which implements the IDisposable interface (or whatever name) and in the deactivate procedure walk the object tree (session:first-object, next-sibling) and call the Dispose method of every class which implements the IDisposable interface, but with persistent procedures something similar is possible.

Posted by Patrick Tingen on 19-Apr-2016 07:31

The solution with the FINALLY block actually sounds good. It would mean the smallest amount of changes and a FINALLY block is reliable enough to close the files.

The solution with a procedure walker would not work I think. If the process is terminated, I end up with a file lock on OS level which will not be released when I kill the process. I think.

Posted by Mike Fechner on 19-Apr-2016 07:45

"Does 10.2B have the finally block?"

Yes. Finally was added in 10.1C.

Posted by Mike Fechner on 19-Apr-2016 07:46

"The solution with the FINALLY block actually sounds good. It would mean the smallest amount of changes and a FINALLY block is reliable enough to close the files."

Reliable, unless there is a STOP condition.

Posted by GregHiggins on 19-Apr-2016 14:58

And in that case I would use a doeul block.

do on error undo, leave on stop undo, leave on quit undo, leave:

 output [stream] ...

 ...

end.

catch e as Error:

 /* log error */

end /* catch e */.

finally:

  output [stream] ... close.

end finally.

/* checked my notes, should be leave here.  on error can be undo, leave or undo, throw  which you would use depends */

This thread is closed