Slf4jLogger class (com.iscobol.logger.Slf4jLogger)
The isCOBOL runtime can trace the runtime activity into a log file. There are different trace levels available. Depending on the trace level environment settings, called programs, file i/o and SQL can be included in the trace or discarded. The trace level is set through the property
iscobol.tracelevel.
By default the trace is saved to a disk file whose name it’s specified by the configuration property
iscobol.logfile. It’s possible to make the runtime send all the trace information to a class that implements the
com.iscobol.logger.Logger interface. In this case it will be a duty of this class to manage the trace by saving it to file or by performing other actions.
The class name must be specified through the configuration property
iscobol.logclass. When this property is set, the runtime sends the trace information to the class specified by the property instead of writing the information to the file indicated by the
iscobol.logfile property.
Currently there is only one class that implements the com.iscobol.logger.Logger interface; this class is included in the isCOBOL runtime library, it’s named com.iscobol.logger.Slf4jLogger and it’s a bridge to the Self4J logger.
In order to use this class, set:
iscobol.logclass=com.iscobol.logger.Slf4jLogger |
Example using Log4j 2
In the following example we make the isCOBOL runtime send the trace information to the Slf4jLogger class that will produce a log split into multiple gzipped files. It creates a new file every time the log size reaches 1 MB. The writing to the log is asynchronous.
Classpath setting
The following additional libraries must appear in the Classpath for a correct result:
Library | Description |
---|
slf4j-api-1.7.32.jar | The Slf4j API |
log4j-slf4j-impl-2.16.0.jar | The Slf4j bridge to Log4j |
log4j-api-2.16.0.jar log4j-core-2.16.0.jar | The Log4j 2 API |
Log4j 2 configuration
A file named log4j2.xml must appear in the Classpath. Put the following content into it in order to activate rolling and zipping of the log file:
<?xml version="1.0" encoding="UTF-8"?> <Configuration> <Appenders> <RollingRandomAccessFile name="RandomAccessFile" fileName="isc.log" filePattern="isc-%d{yyyy-MM-dd}-%i.gz" immediateFlush="false" append="true"> <PatternLayout> <Pattern>%d{yyyy-MM-dd HH:mm:ss} - %m%n</Pattern> </PatternLayout> <Policies> <SizeBasedTriggeringPolicy size="1 MB"/> </Policies> </RollingRandomAccessFile> </Appenders> <Loggers> <Root level="info" includeLocation="false"> <AppenderRef ref="RandomAccessFile"/> </Root> </Loggers> </Configuration> |
Note - Refer to Log4j 2 documentation for more information about the above entries and other possible entries.
Runtime
For this example, we’re going to run the isCOBOL I/O performance test, installed along with isCOBOL. You can find it in the isCOBOL installation directory under the sample/io-performance subdirectory.
Run the following command:
iscrun -J-Discobol.tracelevel=11 -J-Discobol.logclass=com.iscobol.logger.Slf4jLogger IO_INDEXED |
If everything was configured correctly, you should find a similar list of files in the current folder:
isc-2021-10-11-1.gz isc-2021-10-11-2.gz |
Note - the file name might be a little different, depeding on the date and time when you run the test.