Simple logging to a file

Sometimes it’s needed to have a simple logging mechanism, especially, if you want to find a hard to find bug, the exact place of the bug. For that i wrote a simple logging function. Add the fct. to a couple of code positions giving the current name of the trigger as parameter. At the end you get a long list of logging entries, with which it is quite easy to check what’s going on in your code.

// variables
file | File
fileName | Text | 250
LF | Char
CR | Char

// Logging function
fct. WriteLogQEntry(TriggerName : Text[30])
LF := 10;
CR := 13;
fileName := ‘c:\temp\logging.txt’;
file.TEXTMODE(TRUE);
IF NOT EXISTS(fileName) THEN
file.CREATE(fileName)
ELSE BEGIN
file.WRITEMODE(TRUE);
file.OPEN(fileName);
file.SEEK(file.LEN – 1);
file.TRUNC;
END;
file.WRITE(FORMAT(CURRENTDATETIME) + ‘: ‘ + TriggerName + ‘: ‘ + );
file.WRITE(FORMAT(CR,0,”));
// if needed, add following line
// file.WRITE(FORMAT(LF,0,”));
file.CLOSE;

Advertisements

One thought on “Simple logging to a file

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s