Monday, August 21, 2006

Tip -- PeopleTools: Application Engine Logging

Application Engines have the ability to write to the "Redirected Terminal Output". But, everything that is written into it must be written with a MessageBox command. That results in a blank line between messages and the infamous message set ids at the end.

If you want any formatting at all you should open a file and use the File object to create the file.

First, declare the variable in every PeopleCode program in your App Engine:

Component File &logFile;
Declare the variable as a component or global variable so that it stays around for the life of the App Engine program. Otherwise, you will have to keep reopening the file to write to it in each PeopleCode step.

Second, create an Init step in the Main section that will open the file:

&logFile = GetFile(GetEnv("PSPRCSLOGDIR") "\logFile.txt", "W", %FilePath_Absolute);

PSPRCSLOGDIR is the environment variable that is set to the path where the files should go. Every file that is put in this path will be copied to the web server so that the user can see it.

You can use %Filepath_Relative in many cases, but sometimes the relative path does not point to the proper folder, particullarly on older PeopleSoft systems. I have had more success with PSPRCSLOGDIR.

Third, close the file in a step at the end of the Main section:

&logFile.close();

Finally, write what you want to the file with:

&logFile.writeline("This is a log statement!");

You have complete control of this file and can make it say what you want it to.


This post has moved to Wordpress.

No comments: