Application Logging

Error handling and application logging are the most import tasks associated with programming that are over looked by many developers.

After a program is released to the field, how do you know if it is performing as it should? Are there issues with the language execution (1-tier), with the database (2-tier) or with the middle-ware (3-tier) ? Many times, issues are only noticed and acted upon after several complaints have been issued.

Here is a short list of why you should adding logging to all programs that you create.

  • Traps program execution for tracing down coding causing the error.
  • Traps error events for follow up by developers before users complain.
  • If captured in windows event log, 3rd party tools can harvest logs to one central server.
  • Dashboards created at the central server can show the heart beat of your whole infrastructure.

The original application logging CLASS that I wrote in Visual Basic writes to both a local file and the windows event log. There is no equivalent PERL PACKAGE that does just that. Therefore, I am going to build the PERL package to over come this deficiency.

The following example creates a sample package named MyLog to write a string to a file.

We need to tell PERL where our custom pakage is located by using the use lib statement.

The new module is already in the name space of the PERL script. We just need to set the properties of the file name and message before calling the Write() method.

The table below has complete application logging code that you can use in your next PERL Script. I used the CPAN module (Win32::OLE) to leverage the Windows Scripting module. This technique opens up all the windows objects that you call in Visual Basic Script to PERL. App Log Package Sample App Log Program
MyApp.log Sample log file
perl warning Windows event entry




In summary, creating user defined packages allows you to create objects that can be easily reused. In fact, an advance technique would be the compiling of the PERL package for distribute to others. This advance task is out of scope for this talk. Adding application logging to your scripts will save you time in the long run when there are application, database, middle-ware or network issues plaguing your company.

Related posts

Leave a Comment