universeu2

Better cleanup after protocolLogging() on UniVerse?


I have a Basic program that is used to send email via a web service. I want to leverage the protocolLogging() function to catch any issues that sometimes arise when interacting with a web service. However, I don't want to be flooded with all the success logs (right now I'm generating one log file every time the program executes). With the log level set to 3 (or 1 for that matter), an empty file is still generated after a successful run.

Is there a way to prevent the empty log files from being generated in the first place?

If not, is there a better way to clean them up than opening the log directory in the program and deleting the record that was just created (assuming everything else ran successfully)? My log directory is not currently a UniVerse type-19 file or anything.

Is it better to reuse one log file throughout the day? If I change the code to do this, are there any performance implications? This program is a subroutine that gets used heavily at times.

I'm running UniVerse v11.2.3 on Windows Server 2008 R2.


Solution

  • When you use protocolLogging() you are not going to gain any speed advantages logging everything to one file vs multiple files like you have. When you turn the logging on, it still opens a file, and then when you turn the logging off, it will still write and close the file when you have a single log file.

    There are 3 ways you can clean up junk files.

    1) Create a .BAT file to run at the end of the day in Windows Scheduler

    cleanupemptylog.bat
    for %F in ("c:\ud\TEST\*.log") do if %~zF equ 0 del "%F"
    

    2) Use a UniVerse Phantom process to do the same thing. You can create a subroutine that do better checks if you want.

    3) Run the same command at then end of your current Subroutine:

    EXECUTE '!for %F in ("*.log") do if %~zF equ 0 del "%F"'
    

    This will add overhead to your existing subroutine, but it may not be noticeable.

    If you want to use a single log based on the current date, then you would could just cleanup the logs on a monthly basis using a phantom or windows scheduler.

    ie. delete all log file that are more than 5 days old.

    forfiles -p ""c:\ud\TEST\*.log"" -s -m *.* -d -5 -c "cmd /c del @path"
    

    Nathan Rector
    International Spectrum
    http://www.intl-spectrum.com