Introduction
JS7 does not make use of files for log output of order logs and task logs.
- Files are a frequent source of error as they might not be created due to restrictions of disk space or permissions.
- If a log file cannot be created then this could block processing of jobs. Even worse, if log files are not available then users are blind about job execution results.
JS7 therefore streams log output from Agents to the Controller and to JOC Cockpit without use of files.
- Streaming makes job log output available to JOC Cockpit within 1s.
- Streaming allows a running log which translates to the fact that users observe ongoing log output of orders and jobs in the log view window.
- In case of missing connections
- between Controller and Agent then the Agent stores log output in its journal and forwards logs when reconnected to a Controller later on.
- between JOC Cockpit and Controller then the Controller stores log output in its journal and forwards logs when reconnected to JOC Cockpit later on.
Scope
A number of users prefer to have log files available for each order execution and job execution, for example to consolidate log files on a file server or to submit log files to specific tools for log analysis.
- Log analysis is useful but usually comes too late. It's more a reporting activity that is not intended to replace near-real time monitoring.
- Log analysis starts when the log is completed.
- Log analysis is useful when it comes to parsing logs for unexpected output or errors. However, it might prove tedious to teach a log analyzer recovery of errors from log output in case that a job was successfully restarted for a specific order.
To support a situation when log output should be consolidated or should be analyzed by external tools the JS7 - REST Web Service API allows access to log output of orders and jobs.
The JS7 - PowerShell Module is a lightweight wrapper for the REST Web Service API that is used for the below examples.
Order Logs
Order logs include the task log output of each job included in a workflow. This provides better context that use of individual task logs.
The following cmdlets are provided:
$logs = Get-JS7OrderHistory | Get-JS7OrderLog
Explanation:
- The
Get-JS7OrderHistory
cmdlet returns history results that can be filtered by folders, workflows, date range, order states etc. By default today's order executions are returned. - The
Get-JS7OrderLog
cmdlet is used in a pipeline and returns the order log for each history entry. - As a result the
$logs
array holds the list of order logs.
Task Logs
The following cmdlets are provided:
Access Task Log Object
$logs = Get-JS7TaskHistory | Get-JS7TaskLog
Explanation:
- The
Get-JS7TaskHistory
cmdlet returns history results that can be filtered by folders, workflows, date range, jobs, see cmdlet description. By default today's task executions are returned. - The
Get-JS7TaskLog
cmdlet is used in a pipeline and returns the task log object for each history entry. - As a result the
$logs
array holds the list of task log objects.
A task log object holds the following elements:
PS > $logs = Get-JS7TaskHistory | Get-JS7TaskLog PS > $logs[0] controllerId : jobscheduler agentUrl : http://apmaccs:4449 taskId : 15247 orderId : #2022-03-06#P31960629618-pdCyclicSimpleWorkflowTicking workflow : /ProductDemo/CyclicExecution/pdCyclicSimpleWorkflowTicking position : 0/cycle+end=1646607600000,scheme=1,i=10,next=1646564721361:2 job : job3 criticality : normal exitCode : 0 state : @{severity=6; _text=SUCCESSFUL} startTime : 06.03.2022 12:05:31 endTime : 06.03.2022 12:05:36 log : 2022-03-06 12:05:31.388+0100 [MAIN] [Start] Job=job3, Agent (url=http://apmaccs:4449, id=agent_002) 2022-03-06 12:05:31.795+0100 [STDOUT] using workflow: pdCyclicSimpleWorkflowTicking running job: job3 2022-03-06 12:05:36.399+0100 [MAIN] [End] [Success] returnCode=0
Write Task Log to File
Get-JS7TaskHistory | Get-JS7TaskLog | Out-File /tmp/history/tasks.log -Encoding Unicode
Explanation:
Read the logs of today's tasks and write the logs to a common file.
Get-JS7TaskHistory -RelativeDateFrom -8h | Get-JS7TaskLog | Select-Object @{name='path'; expression={ "/tmp/history/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path]::GetFileNameWithoutExtension($_.job)).log"}}, @{name='value'; expression={ $_.log }} | Set-Content
Explanation:
Read the logs of tasks that completed within the last 8 hours and writes the log output to individual files. The log file names are created from the start time and from the job name of each task.