Application Engine Log File

Handy little library to open Application Engine log files, based on whether running on client while developing, or on server.

class FuncLib
   method isTestingMode(&iProcessInst As integer) Returns boolean;
   method GetFile(&bTesting As boolean, &sFilename As string, &sMode As string) Returns File;
end-class;


/**********************************************************************
 * Returns whether app engine is in test mode (running locally).      *
 * -------------------------------------------------------------------*
 * Parameters  : &numProcessInst (process instance)               *
 * Returns   : True if running locally, otherwise false.              *
 **********************************************************************/
method isTestingMode
   /+ &iProcessInst as Integer +/
   /+ Returns Boolean +/
   Local boolean &bExists, &bTestMode;
   
   /* Check if process instance exists in a process scheduler table */
   SQLExec("SELECT 1 FROM PSPRCSRQST WHERE PRCSINSTANCE = :1", &iProcessInst, &bExists);
   
   If Not &bExists Then
      /* If not, then its running in test mode. */
      &bTestMode = True;
   End-If;
   
   Return &bTestMode;
end-method;


/**********************************************************************
 * This method creates/opens a log file when running an app engine    *
 * in either 2 (testing) or n tier mode.                              *
 * -------------------------------------------------------------------*
 * Parameters                                                         *
 *   Parm 1:  Boolean - Testing mode?                                 *
 *   Parm 2:  File name                                               *
 *   Parm 3:  Mode: "W" will create a new file for writing,           *
 *                       "A" will append to an existing file.         *
 * Returns : File                                                     *
 **********************************************************************/
method GetFile
   /+ &bTesting as Boolean, +/
   /+ &sFilename as String, +/
   /+ &sMode as String +/
   /+ Returns File +/
   
   Local string &sPath;
   Local File &fFile;
   
   If &bTesting Then
      &sPath = "C:\TEMP\";
      &fFile = GetFile(&sPath | &sFilename, &sMode, %FilePath_Absolute);
   Else
      &sPath = "";
      &fFile = GetFile(&sFilename, &sMode);
   End-If;
   
   If &sMode = "W" Then
      MessageBox(0, "", 0, 0, "Creating file:  %1", &sPath | &sFilename);
   End-If;
   
   Return &fFile
end-method;
And to use:

import YOUR_PACKAGE:Utilities:FuncLib:*;

Component File &logFile;

&cbTestingMode = (create YOUR_PACKAGE:Utilities:FuncLib()).isTestingMode(YOUR_STATE_RECORD_AET.PROCESS_INSTANCE);
&logFile = (create YOUR_PACKAGE:Utilities:FuncLib()).GetFile(&cbTestingMode, "log.txt", "W");

0 comments: