Add debug logging to stream output and incorporate into test.