Circular Logging for Deployed Applications

Added in Flex2SQL 18.1.

Circular logging lets you leave a driver trace enabled while limiting the growth of an individual log file. It is useful for intermittent production errors that are difficult to reproduce while detailed tracing is enabled.

For routine deployment diagnostics, use errors-only level -1, named ERROR_LEVEL in DataFlex commands, with circular mode. This records errors and warnings without the normal stream of database operations. Diagnostic headers and some driver status messages are still included. It is a driver diagnostic log, not a complete application or audit log.

Use DEBUG_LEVEL or the detail levels temporarily when you need the operations leading up to an error. Circular mode limits file growth but does not remove the processing and I/O cost of detailed tracing.

How Circular Mode Works

When the current write position reaches the configured size, the driver rewinds to the beginning of the same file and starts overwriting earlier content. It writes the trace header again and a Circular logging - Cycle: N marker.

  • The threshold is specified in MB (1 MB = 1,024 x 1,024 bytes). The default threshold is 500 MB; a non-positive size falls back to that default.

  • The check takes place after writes, so the file can slightly exceed the threshold. It is not an exact byte quota.

  • The driver does not create numbered archives. After a wrap, the current cycle is at the beginning and an older cycle’s tail can remain until overwritten. Use timestamps and cycle markers when reading the file; the physical end is not necessarily the newest event.

  • Opening or re-enabling a trace at the same filename starts a fresh file. Copy a useful trace before restarting or reconfiguring it.

  • A size setting alone does not bound file growth: circular mode must also be enabled. Circular mode applies to file output, not debug://.

Setup with MERTECH.INI

Create a writable log directory and add the following to the appropriate driver section of mertech.ini. This example uses SQL Server:

[MSSQL]
TRACE_ON = C:\Logs\OrderEntry-errors.log
TRACE_LEVEL = -1
TRACE_CIRCULAR_MODE = yes
TRACE_FILE_MAX_SIZE = 50
TRACE_FLUSH = yes

Use [ORACLE], [PGSQL], or [MYSQL] for the corresponding driver. Start or restart the application so the driver reads these settings.

TRACE_FLUSH = yes flushes buffered trace output promptly, which helps retain the most recent messages if the application terminates unexpectedly. It adds I/O overhead and does not guarantee recovery of every message after a crash. The ordinary trace default is no.

The application or service account needs permission to create and write the file. The driver does not create missing directories. If it cannot open the file, file tracing is not enabled.

Setup with Environment Variables

Set these in the environment inherited by the application before the driver loads. For a Windows command prompt:

SET TRACE_ON=C:\Logs\OrderEntry-errors.log
SET TRACE_LEVEL=-1
SET TRACE_CIRCULAR_MODE=1
SET TRACE_FILE_MAX_SIZE=50
SET TRACE_FLUSH=1

For a supported Linux driver:

export TRACE_ON=/var/log/myapp/orderentry-errors.log
export TRACE_LEVEL=-1
export TRACE_CIRCULAR_MODE=1
export TRACE_FILE_MAX_SIZE=50
export TRACE_FLUSH=1

The directory must already exist and be writable by the application’s user.

For a Windows service, configure the service process’s environment and restart it; setting variables in an unrelated command prompt will not affect an already running service.

Avoid conflicting trace settings. A nonempty TRACE_ON in mertech.ini selects the INI-configured trace during initialization. Environment variables TRACE_LEVEL and TRACE_FLUSH are read when the trace header is written and can override the corresponding INI or programmatic settings. Check the resulting header for the actual level and circular size.

Setup in Application Code

With the intended driver already loaded and selected:

ENABLE_TRACE_ON to "C:\Logs\OrderEntry-errors.log" ERROR_LEVEL CIRCULAR_MODE 50

Use the symbolic ERROR_LEVEL in the command. The numeric -1 is used in INI and environment settings; it is not a substitute for the command’s level keyword.

The command takes the level, then CIRCULAR_MODE, then the size in MB. Use the 18.1 include/package files and driver for these new options. The earlier command form without circular options remains supported.

To stop tracing:

DISABLE_TRACE_ON

See ENABLE_TRACE_ON for all levels and parameters. Programmatic tracing starts after that command executes. Use startup configuration when you need to capture errors during driver initialization or initial login.

Setup with the Mertech Trace Utility

On Windows, select the appropriate product and the Driver tab, enable Enable Trace, select file output and a filename, and choose Errors Only for Level. Enable Circular Mode, set Max Size (MB), and click Save.

For WebApp and service deployments, use INI settings or the service’s environment instead of relying on the interactive Trace Utility.

Checking and Collecting a Trace

Check that the file exists and that its header reports Trace Level: -1 (circular) and your selected maximum size. After an incident, collect the log promptly before later activity overwrites the relevant cycle. Include the time of the incident when sending it to Mertech Support.

Give concurrently running application instances separate trace filenames. Circular mode limits each file, not the combined size of all files on disk. Apply a retention policy to logs copied for support or created by successive application starts.