Viewing Java batch job logs

When you are running Java batch jobs in the WebSphere Application Server Liberty, a log is written for each job.

The logs are created in the following directory structure:

log directory/joblogs/job name/date/instance.job instance ID/execution.execution ID

Attention: The variable job name is the id attribute of the job element within the JSL (XML) document. It is not necessarily related to the file name of the JSL file.
The naming of logs begins at part.1.log and rotates to new log parts as needed. By default, the job log contains all messages and trace information that is logged in the server by the thread that is performing the job execution. Output that is not logged within the java.util.logging framework is not collected.
Important: If a new log part cannot be created, batch attempts to continue processing without a log, or with the current log part.

For more information about retrieving or deleting job logs by using the REST API, see the REST API administration documentation.

Important: If you use the log4j API, applications that use the log4j framework can participate in batch job logging by using org.apache.log4j.jul.JULAppender. The JULAppender forwards log4j log records to the java.util.logging framework, where they are collected for job logging.

Configuring job logging

Batch job logging can be configured by using the <batchJobLogging> configuration element <batchJobLogging enabled="true" maxRecords="1000" />.

The attribute maxRecords indicates the number of records that are written to a job log part before the records roll over to the next part.

The batch feature uses a logger that is named com.ibm.ws.batch.JobLogger to log certain batch messages to the job log only. Examples include job lifecycle messages and checkpoint messages. The logger does not write to the server log. By default, the logger is enabled for Level.FINE messages. You can configure the level of the logger by specifying it in the trace specification of the server. For example, <logging traceSpecification="*=info:com.ibm.ws.batch.JobLogger=all" />.

Any log messages that are written by the job thread, including messages that are written by the run time and by application code, are written to both the job log and the server log.

The System.out and System.err files are only written to the server log and are not written to the job log.

Partitioned steps

Partitioned steps have more subdirectories for each partition. The log files in the execution ID directory contain entries from the thread that is running the top-level job. The job logs for the partitions are stored with the following structure:

log directory/joblogs/job name/date/instance.job instance ID/execution.execution ID/name of partitioned step/partition number

Important: A directory is created in the name of partitioned step directory for each partition.

Split flows

If a split flow occurs in the job, more subdirectories are created to capture the output from the thread of each flow. The log files that are located directly under the execution ID directory contains entries from the thread that is running the top-level job. The job logs for individual flow threads are stored with the following structure:

log directory/joblogs/job name/date/instance.job instance ID/execution.execution ID/split ID/flow ID

Important: A directory is created in the split ID directory for each flow.

Job log events

If batch job events are enabled, then job log events are published when a job log part is completed and when a job goes to an ended state, such as stopped, failed, or completed. The job log event messages contain multiple JSON properties to help with identifying the message along with the actual job log file content.

Important: The JSON properties are part of the JMS message body and can be retrieved by converting the body text to a JsonObject and pulling the specific JSON property from that object.
The following example illustrates how to retrieve the job log content property.
//The retrieved job log event message
Message msg
//Convert the Message to a TextMessage
TextMessage txtMsg = (TextMessage) msg;
//Convert the text in the message to a JsonObject
JsonObject jobLogEventObject = Json.createReader(new StringReader(txtMsg.getText())).readObject();
//Pull the job log text content from the JsonObject as an example
JsonArray logContentArray = jobLogEventObject.getJsonArray("contents");

For more information about enabling batch job events, see Enabling batch job events publishing.