LogBuf() - High Performance Logging

Anonymous
Anonymous

High speed logging with minimal disk/CPU impact

Version
1.05

Requirements
Citect v5 - v7

Description
LogBuf() is meant for trace-level logging from Cicode functions which would normally bog Citect down with too much logging.

You can use the ErrLog() function to log text messages to the syslog.dat file, but that can slow down the runtime if a lot of information is being logged. It can also be hard to find what you're looking for if too much other information is also logged there. This Cicode function allows you to specify any text string to log, and any System Device (ASCII type) to log it to. You can also specify a severity level for each message (error, info, trace, etc.) and change which severity levels are being logged with a Citect.ini parameter without restarting Citect.

The function returns immediately, and starts a separate task to do the actual logging. This task waits for more messages to be queued up, then logs them in as few large writes (254 chars) as possible, which is more efficient than doing many small writes. It also sleeps a short time between each write to minimize CPU and disk usage. Messages are buffered in a Cicode Queue so multiple threads may be sending log messages for one or more System Devices simultaneously. If more than 5,000 messages are queued up before they can be logged, the sleep is eliminated to ensure the queue does not grow faster than it is written to disk.

Note that when running in multiprocess mode, multiple Citect runtime processes should not be logging to the same device/file.

Updates

v1.05 Added message level filtering. Moved Date Format argument to a parameter--note that existing code may need to be modified
v1.04 Added default datestamp for messages
v1.03 Set max messages limit based on [Code]Queue parm to avoid overflowing small queue sizes. Added extra error messages. 

Author
Eric Black

Submitter
Eric Black

Attachments