# How To Capture CopyStorm Runtime Logs

This article provides information on how to capture CopyStorm job execution log data that is output via Standard Error/Out in a text file. This approach is useful for doing advanced troubleshooting in order to capture error symptoms that may not appear within the application GUI or within the logged exceptions of the job history entry found on the “History” tab.

The general approach is as follows:

1. Open a headless CopyStorm script for editing.
   1. This is the script that is scheduled using CRON or Windows Task Scheduler, and is created using the “Batch File” tab of CopyStorm.
2. Create a directory that will be used to save the application logs.
3. Edit the batch script to create a log file with the appropriate name in the established directory and write all job execution output to the file.

## Windows

Here is an unedited example of a Windows batch script generated by CopyStorm. This script will be modified to output CopyStorm job logs to a file:

```
@ECHO OFF
REM 
REM This script runs CopyStorm and relies on the notification system built into CopyStorm
REM to report the success/failure of a job. Log file information is written to stdout 
REM in addition to the logging tables in the CopyStorm database.
REM 
REM    CopyStormRootDir - the directory in which CopyStorm is installed.
REM    CopyStormConfigFile -- the name of the CopyStorm configuration file to run.

SET CopyStormRootDir=C:\Capstorm\CopyStorm
SET CopyStormConfigFile=C:\Capstorm\CapstormConfig\config.copyStorm

SET CopyStormCmd="%CopyStormRootDir%\CopyStorm.bat" -run "%CopyStormConfigFile%" 
CALL %CopyStormCmd% 2>&1

EXIT /B %ERRORLEVEL%
```

The following code is added after the line that begins with “SET CopyStormConfigFile”

* ```
  SET LOGDIR=C:\Capstorm\CopyStormLogs
  ```
  * This code sets a local script variable that establishes the path to the directory where the log files will be stored.
  * The “C:\Capstorm\CopyStormLogs” path should point to your desired CopyStorm log directory path.
* ```
  SET TIMESTAMP=%date:~10,4%-%date:~7,2%-%date:~4,2%T%TIME::=-%
  SET TIMESTAMP=%TIMESTAMP: =0%
  ```
  * This code sets a local script variable to the current timestamp at which the script is executed. Timestamps will be generated using YYYY-MM-DDTHH-mm-SS.SS formatting – e.g. “2023-02-21T19-45-32.12”.
  * You do not need to change any of this code, just copy and paste it directly.

Next, the second to last line (starting with “CALL %CopyStormCmd%”) will need to be modified to write to the logfile. The final line will look like this:

* ```
  CALL %CopyStormCmd% >> %LOGDIR%\CopyStorm_Log_%TIMESTAMP%.txt 2>&1
  ```

This code creates a logfile and redirects stderr and stdout to the file, capturing all job execution logs.

The “CopyStorm\_Log\_” prefix is used to identify the type of logfile – if you have multiple scheduled jobs, it is best practice to use a different prefix for each scheduled job. For example, “CopyStorm\_Hourly\_Data\_” and “CopyStorm\_Daily\_Metadata\_” if there is an hourly job for data and a separate daily job for metadata.

The example above will create log files with names like:

* CopyStorm\_Log\_2023-02-21T19-45-32.txt

Here is an edited version of the batch script shown above:

```

@ECHO OFF
REM
REM This script runs CopyStorm and relies on the notification system built into CopyStorm
REM to report the success/failure of a job. Log file information is written to stdout
REM in addition to the logging tables in the CopyStorm database.
REM
REM CopyStormRootDir - the directory in which CopyStorm is installed.
REM CopyStormConfigFile -- the name of the CopyStorm configuration file to run.

SET CopyStormRootDir=C:\Capstorm\CopyStorm
SET CopyStormConfigFile=C:\Capstorm\CapstormConfig\config.copyStorm

SET LOGDIR=C:\Capstorm\CopyStormLogs
SET TIMESTAMP=%date:~10,4%-%date:~7,2%-%date:~4,2%T%TIME::=-%
SET TIMESTAMP=%TIMESTAMP: =0%

SET CopyStormCmd="%CopyStormRootDir%\CopyStorm.bat" -run "%CopyStormConfigFile%"
CALL %CopyStormCmd% >> %LOGDIR%\CopyStorm_Log_%TIMESTAMP%.txt 2>&1

EXIT /B %ERRORLEVEL%

```

## Linux

Here is an unedited example of a Linux sh script generated by CopyStorm. This script will be modified to output CopyStorm job logs to a file:

```

#!/bin/sh
#############################################################################

# This script runs CopyStorm and relies on the notification system built into CopyStorm

# to report the success/failure of a job. Log file information is written to stdout

# in addition to the logging tables in the CopyStorm database.

#

# CopyStormRootDir - the directory in which CopyStorm is installed.

# CopyStormConfigFile -- the name of the CopyStorm configuration file to run.

#
#############################################################################

CopyStormRootDir="/opt/Capstorm/CopyStorm"
CopyStormConfigFile="/opt/Capstorm/CopyStormConfig/configFile.copyStorm"

sh $CopyStormRootDir/CopyStorm.sh -run $CopyStormConfigFile 2>&1

exit $?

```

The following code is added after the line that begins with “CopyStormConfigFile=”

* ```
  LOGDIR="/opt/Capstorm/CopyStormLogs"
  ```
  * This code sets a local script variable that establishes the path to the directory where the log files will be stored.
  * The “/opt/Capstorm/CopyStormLogs” path should point to your desired CopyStorm log directory path.
* ```
  TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S")

  ```
  * This code sets a local script variable to the current timestamp at which the script is executed. Timestamps will be generated using YYYY-MM-DDTHH:mm:SS formatting – e.g. “2023-02-21T19:45:32”.
  * You do not need to change any of this code, just copy and paste it directly.

Next, the second to last line (starting with “sh $CopyStormRootDir”) will need to be modified to write to the logfile. The final line will look like this:

* ```
  sh $CopyStormRootDir/CopyStorm.sh -run $CopyStormConfigFile >> "$LOGDIR/CopyStorm_Log_$TIMESTAMP.txt" 2>&1
  ```

This code creates a logfile and redirects stderr and stdout to the file, capturing all job execution logs.

The “CopyStorm\_Log\_” prefix is used to identify the type of logfile – if you have multiple scheduled jobs, it is best practice to use a different prefix for each scheduled job. For example, “CopyStorm\_Hourly\_Data\_” and “CopyStorm\_Daily\_Metadata\_” if there is an hourly job for data and a separate daily job for metadata.

The example above will create log files with names like:

* CopyStorm\_Log\_2023-02-21T19:45:32.txt

Here is an edited version of the batch script shown above:

```
#!/bin/sh
#############################################################################
# This script runs CopyStorm and relies on the notification system built into CopyStorm
# to report the success/failure of a job. Log file information is written to stdout 
# in addition to the logging tables in the CopyStorm database.
#
#   CopyStormRootDir - the directory in which CopyStorm is installed.
#   CopyStormConfigFile -- the name of the CopyStorm configuration file to run.
#
#############################################################################

CopyStormRootDir="/opt/Capstorm/CopyStorm"
CopyStormConfigFile="/opt/Capstorm/CopyStormConfig/configFile.copyStorm"

LOGDIR="/opt/Capstorm/CopyStormLogs/"
TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S")

sh $CopyStormRootDir/CopyStorm.sh -run $CopyStormConfigFile >> "$LOGDIR/CopyStorm_Log_$TIMESTAMP.txt" 2>&1

exit $?
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.capstorm.com/frequently-asked-questions/usage/how-to-capture-copystorm-runtime-logs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
