Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

JS7 does not make use of files for log output of order logs and task logs, see see the JS7 - Order Logs and Task Logs. JS7 instead article for detailed information. Instead, JS7 streams log output from Agents to the Controller and to the JOC Cockpit without the use of files.

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.

To support a situation when log output should be consolidated to files, 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 examples below examples with on Linux and Windows. Users are free to use the JS7 REST Web Service from their preferred scripting language to provide similar functionality.

For similar handling of task logs Task logs can be handled similarly - see JS7 - How to make task logs available from files.

...

Order logs include the task log output of each job and instruction instructions included in a workflow. This provides better a context than the use of individual task logs.

...

  • The Get-JS7OrderHistory cmdlet returns history results that can be filtered by folders, workflows, date range, order states, see cmdlet description linked above. By default today's order executions are returned.
  • The Get-JS7OrderLog cmdlet is used in a pipeline and returns the order log object for each history entry.
  • As a result the $logs array holds the list of order log objects.

...

An order log object carries a number of attributes as visible from can be seen in the following console example:

...

  • Provides a mechanism to subsequently retrieve previous logs. Starting from initial execution of the Get-JS7OrderHistory cmdlet the resulting $lastHistory object is used for any subsequent calls.
    Consider use of the Tee-Object cmdlet in the pipeline that updates the $lastHistory object that which can be used for later executions of the same pipeline.
  • This pipeline can e.g. , for example, be executed in a cyclic job.

...

A workflow is created that runs the commands mentioned above commands in a cycle. The workflow operates 24/7 and writes order logs to files.

...

  • The first job get-history-order-logs is executed at the point in time when the order arrives that which starts the workflow arrives.
    • This job determines the last history entry from which to start.
  • The second job write-order-logs-to-files is executed within a JS7 - Cycle Instruction:
    • The above example implements a ticking cycle every 30 minutes. For a 24h period the job will repeat every 30 minutes. 
    • Users can adjust the cycle at their willas required.


The first job get-history-order-logs looks like this:

...

  • Line 1: The shebang is required to identify PowerShell being as the interpreter of the script. The above example is for Unix, for Windows the first line of the job script should be replaced as follows:
    • Code Block
      languagepowershell
      titleExample of shebang for PowerShell with Unix
      linenumberstrue
      #!/usr/bin/env pwsh
    • Code Block
      languagepowershell
      titleExample of shebang for PowerShell with Windows
      linenumberstrue
      @@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof
  • Line 4: The are a number of ways how to specify of specifying the details for a JS7 connection , see - see the JS7 - How to connect to JOC Cockpit using the PowerShell Module article.
    • The host and port are specific for a user's environment.
    • The Controller ID is specified during installation of the Controller and defaults to Controller.
  • Line 9: A workflow variable is created that carries the list of order log objects returned by the Get-JS7OrderHistory cmdlet for which task logs should be created for. This variable is in fact a PowerShell object that is serialized to JSON and prefixed with the string json: for later use with the second job in the workflow.

...

Code Block
languagepowershell
titleExample for job write-order-logs-to-files
linenumberstrue
#!/usr/bin/env pwsh

Import-Module JS7
Connect-JS7 -Url http://root:root@localhost:4446 -Id Controller | Out-Null

    # restore object from json by a temporary file
    $lastHistory = ( (Get-Content $env:LAST_HISTORY_FILE).Substring(5) | ConvertFrom-Json )

Get-JS7OrderHistory -DateFrom $lastHistory[0].startTime | Tee-Object -Variable lastHistory | Get-JS7OrderLog | Select-Object @{name='path'; expression={ "/tmp/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path]::GetFileNameWithoutExtension($_.workflow))-$($_.orderId).order.log"}}, @{name='value'; expression={ $_.log }} | Set-Content

    # forward a variable for the object
    "lastHistory=json:$($lastHistory | ConvertTo-Json -Compress)" | Out-File $env:JS7_RETURN_VALUES -Append

Disconnect-JS7


Explanation:

  • Lines 1, 4: Same The same explanations apply as for the previous job.
  • Lines 7: The variable holding the list of order log objects of the last processing of this job is restored from a temporary file that which holds the JSON representation of the objects. The temporary files is are provided by the JS7 Agent and is are referenced from an environment variable that which is assigned the workflow variable like this.


  • Line 10: When reading the order history then , the variable carrying the list of order log objects is updated and is and  forwarded to the workflow for next execution of the cycle.

...