Skip to content

Commit c7ce061

Browse files
hanniavaleraHannia Valera
andauthored
Improving Logging Behavior (#4770)
* Enhance CMakeOutputConsumer logging: log milestone stdout at info level and routine stdout at debug level * Refactor CMakeOutputConsumer: make milestone regex static and improve comments --------- Co-authored-by: Hannia Valera <[email protected]>
1 parent 8e19cd6 commit c7ce061

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

src/diagnostics/cmake.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ export enum StateMessage {
2121
* in conjunction with `proc.execute`.
2222
*/
2323
export class CMakeOutputConsumer extends CommandConsumer {
24+
/**
25+
* Matches CMake status lines that signal key configure/generate lifecycle
26+
* milestones. These are always logged at `info` so they remain visible at
27+
* the default logging level. All other stdout lines use `debug`, keeping
28+
* the Output panel concise while still being one setting-change away.
29+
*
30+
* Matched patterns (all prefixed with `-- `):
31+
* Configuring done / Configuring done (0.1s)
32+
* Configuring incomplete, errors occurred!
33+
* Generating done
34+
* Build files have been written to: <path>
35+
*/
36+
private static readonly _milestoneRe =
37+
/^-- +(Configuring (done|incomplete)|Generating done|Build files have been written to:)/;
38+
2439
constructor(readonly sourceDir: string, readonly logger?: Logger) {
2540
super();
2641
}
@@ -46,12 +61,18 @@ export class CMakeOutputConsumer extends CommandConsumer {
4661
private readonly _stateMessages: StateMessage[] = [];
4762

4863
/**
49-
* Simply writes the line of output to the log
64+
* Writes the line of output to the log at a tiered level:
65+
* - Milestone lines (configure/generate done, build files written) → info
66+
* - All other CMake stdout → debug
5067
* @param line Line of output
5168
*/
5269
output(line: string) {
5370
if (this.logger) {
54-
this.logger.trace(line);
71+
if (CMakeOutputConsumer._milestoneRe.test(line)) {
72+
this.logger.info(line);
73+
} else {
74+
this.logger.debug(line);
75+
}
5576
}
5677
super.output(line);
5778
this._parseDiags(line);

test/unit-tests/diagnostics.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,16 +1358,33 @@ suite('Diagnostics', () => {
13581358
consumer.dispose();
13591359
});
13601360

1361-
test('CMakeOutputConsumer logs stdout lines at trace level, not info', () => {
1361+
test('CMakeOutputConsumer logs milestone stdout at info and routine stdout at debug', () => {
13621362
const spy = new SpyLogger();
13631363
const consumerWithLogger = new CMakeOutputConsumer('dummyPath', spy);
1364+
// Routine CMake status lines → debug
1365+
consumerWithLogger.output('-- The C compiler identification is GNU 9.3.0');
1366+
consumerWithLogger.output('-- Detecting CXX compiler ABI info');
1367+
// Milestone lines → info
13641368
consumerWithLogger.output('-- Configuring done');
13651369
consumerWithLogger.output('-- Generating done');
1370+
consumerWithLogger.output('-- Build files have been written to: /path/to/build');
1371+
consumerWithLogger.output('-- Configuring incomplete, errors occurred!');
13661372

1367-
const traceCalls = spy.calls.filter(c => c.level === 'trace');
13681373
const infoCalls = spy.calls.filter(c => c.level === 'info');
1369-
expect(traceCalls.length).to.eq(2);
1370-
expect(infoCalls.length).to.eq(0);
1374+
const debugCalls = spy.calls.filter(c => c.level === 'debug');
1375+
const traceCalls = spy.calls.filter(c => c.level === 'trace');
1376+
// 4 milestones at info
1377+
expect(infoCalls.length).to.eq(4);
1378+
expect(infoCalls.map(c => c.args[0])).to.deep.eq([
1379+
'-- Configuring done',
1380+
'-- Generating done',
1381+
'-- Build files have been written to: /path/to/build',
1382+
'-- Configuring incomplete, errors occurred!'
1383+
]);
1384+
// 2 routine lines at debug
1385+
expect(debugCalls.length).to.eq(2);
1386+
// Nothing at trace
1387+
expect(traceCalls.length).to.eq(0);
13711388
});
13721389

13731390
test('CMakeOutputConsumer logs stderr lines at warning level, not error', () => {

0 commit comments

Comments
 (0)