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 tha 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 splitted 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 libraries must appear in the Classpath for a correct result:
Library | Description |
---|
iscobol.jar | The isCOBOL runtime. |
slf4j-api-1.7.19.jar | The Slf4j API. |
log4j-slf4j-impl-2.8.2.jar | The Slf4j bridge to Log4J. |
log4j-api-2.8.2.jar log4j-core-2.8.2.jar | The Log4J 2 API. |
apache-log4j-extras-1.2.17.jar | Log4J extra functions like rolling and zipping. |
Note - slf4j and log4j libraries are not distributed along with isCOBOL. They must be downloaded separately from their web sites.
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-2019-02-12-1.gz isc-2019-02-12-2.gz |
Note - the file name might be a little different, depeding on the date and time when you run the test.
Example using Log4J
In the following example we make the isCOBOL runtime send the trace information to the Slf4jLogger class that will produce a log splitted into multiple gzipped files, one per second.
Classpath setting
The following libraries must appear in the Classpath for a correct result:
Library | Description |
---|
iscobol.jar | The isCOBOL runtime. |
slf4j-api-1.7.19.jar | The Slf4j API. |
slf4j-log4j12-1.7.19.jar | The Slf4j bridge to Log4J. |
log4j-1.2.17.jar | The Log4J API. |
apache-log4j-extras-1.2.17.jar | Log4J extra functions like rolling and zipping. |
Note - slf4j and log4j libraries are not distributed along with isCOBOL. They must be downloaded separately from their web sites.
Log4J configuration
A file named log4j.properties must appear in the Classpath. Put the following content into it in order to activate rolling and zipping of the log file:
log4j.rootCategory=WARN, iscobolAppender log4j.appender.WARN=org.apache.log4j.FileAppender log4j.appender.WARN.File=myLogInfo.log log4j.appender.WARN.layout=org.apache.log4j.PatternLayout log4j.logger.com.iscobol.logger.Slf4jLogger=iscobolAppender, WARN log4j.appender.iscobolAppender=org.apache.log4j.rolling.RollingFileAppender log4j.appender.iscobolAppender.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy log4j.appender.iscobolAppender.RollingPolicy.FileNamePattern=msg.%d{yyyyMMdd.HHmmssSS}.gz log4j.appender.iscobolAppender.layout=org.apache.log4j.PatternLayout |
Note - Refer to Log4J 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:
msg.20160331.112746589.gz msg.20160331.11274778.gz msg.20160331.11274800.gz msg.20160331.11274956.gz msg.20160331.11275000.gz msg.20160331.11275100.gz msg.20160331.11275200.gz msg.20160331.11275300.gz msg.20160331.11275400.gz msg.20160331.11275500.gz msg.20160331.11275600.gz msg.20160331.11275700.gz msg.20160331.11275800.gz msg.20160331.11275901.gz msg.20160331.11280000.gz msg.20160331.11280131.gz msg.20160331.11280200.gz msg.20160331.11280300.gz msg.20160331.11280401.gz msg.20160331.11280500.gz |
Note - the file name might be a little different, depeding on the date and time when you run the test.