Skip to content

Commit 3a510c6

Browse files
committed
chore: improve logging
1 parent 3ffe7fc commit 3a510c6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/testing/src/TestStack.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Console } from 'node:console';
12
import { readFile } from 'node:fs/promises';
23
import { tmpdir } from 'node:os';
34
import { join } from 'node:path';
@@ -11,6 +12,11 @@ import { App, Stack } from 'aws-cdk-lib';
1112
import { generateTestUniqueName } from './helpers.js';
1213
import type { TestStackProps } from './types.js';
1314

15+
const testConsole = new Console({
16+
stdout: process.stdout,
17+
stderr: process.stderr,
18+
});
19+
1420
/**
1521
* Test stack that can be deployed to the selected environment.
1622
*/
@@ -46,6 +52,11 @@ class TestStack {
4652
* Reference to the AWS CDK Cloud Assembly context.
4753
*/
4854
#cx?: ICloudAssemblySource;
55+
/**
56+
* @internal
57+
* Reference to the console object.
58+
*/
59+
static #console: Console;
4960

5061
public constructor({ stackNameProps, app, stack }: TestStackProps) {
5162
this.testName = generateTestUniqueName({
@@ -58,10 +69,16 @@ class TestStack {
5869
color: false,
5970
ioHost: {
6071
async notify(msg) {
61-
console.log(msg);
72+
if (process.env.ACTIONS_RUNNER_DEBUG === 'true') {
73+
testConsole.log(msg);
74+
} else {
75+
if (['info', 'warning', 'error'].includes(msg.level)) {
76+
testConsole.log(msg);
77+
}
78+
}
6279
},
6380
async requestResponse(msg) {
64-
console.log(msg);
81+
testConsole.log(msg);
6582
return msg.defaultResponse;
6683
},
6784
},

0 commit comments

Comments
 (0)