Capturing Errors and Logging
This section shows how to access the different debug reporting available via PoweShell streams.
Accessing Cmdlet Output From Streams
The cmdlet writes data to several PowerShell streams, the Output stream, Error stream, Verbose stream, and Debug stream. Streams enable you to pass the cmdlet results down the pipeline while writing logs to a file or the console.Redirecting Errors and Logs
Only success output and errors are returned by default. However, the cmdlets can write to two other streams, the Verbose stream and, for higher levels of verbosity, the Debug stream.
Verbose Stream
The cmdlets write the underlying SQL queries and the execution time to the Verbose stream. To obtain the Verbose stream from the cmdlet, add the "-Verbose" flag.
Select-IBMCloudSQLQuery -Connection $conn -Table "[CloudObjectStorage_1].[SampleBucket_1].Jobs" -Where "UserId = '[email protected]'" -Verbose
You can capture the output from this stream by using the redirection operator that corresponds to the stream number. The following line uses the "4>" operator to write cmdlet logs to a file:
Select-IBMCloudSQLQuery -Connection $conn -Table "[CloudObjectStorage_1].[SampleBucket_1].Jobs" -Where "UserId = '[email protected]'" -Verbose 4> out.txt
Debug Stream
The Debug stream (stream 5) contains the same information as the Verbose stream as well as more details including the following:
- Time of execution
- Low-level interaction with the API of the data source
- Cache queries
$message = Select-IBMCloudSQLQuery -Connection $conn -Table "[CloudObjectStorage_1].[SampleBucket_1].Jobs" -Where "UserId = '[email protected]'" -Debug 5> out.debug.txt