Skip to content

#94: Add timestamps for maven logs#955

Open
nacNAC333 wants to merge 3 commits into
objectionary:masterfrom
nacNAC333:94-timestamps
Open

#94: Add timestamps for maven logs#955
nacNAC333 wants to merge 3 commits into
objectionary:masterfrom
nacNAC333:94-timestamps

Conversation

@nacNAC333

Copy link
Copy Markdown
Contributor

Fixes #94

Add timestamps to Maven log output for easier debugging.

Changes to src/mvnw.js:

  • Add timestamp() function for [HH:MM:SS] formatted log prefixes
  • Pipe Maven stdout/stderr to add timestamps
  • Makes debugging long builds much easier

@yegor256

Copy link
Copy Markdown
Member

@nacNAC333 Thanks for your contribution! Unfortunately, we can't merge it without tests. Every feature we add and every bug we fix must be accompanied by at least one new test that confirms that the code was not working before. Without such a test, how can we know that what you commit actually works?

@Favixx Favixx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mvnw crashes on every invocation — result.stderr is null

This change makes the mvnw wrapper throw a TypeError on every call, so effectively every eoc command (parse, compile, etc.) fails before Maven even starts.

Setting stdio: ['pipe', 'pipe', 'inherit'] inherits the child's stderr, which means child.stderr is null. The handler added below then dereferences it.

Reproduced on this branch with a minimal call mvnw(['--version']):

TypeError: Cannot read properties of null (reading 'on')
    at src/mvnw.js:127:19
    at new Promise (<anonymous>)

The same call on master runs to completion, so the regression is introduced here.

Additional notes:

  1. Reformatting Maven output line-by-line in JS is lossy (see inline comments). A native approach via slf4j-simple flags (-Dorg.slf4j.simpleLogger.showDateTime=true / -Dorg.slf4j.simpleLogger.dateTimeFormat=...), as in #964/#909, lets Maven emit timestamps itself and preserves formatting.
  2. Per project policy, please add a test that fails before this change and passes after — none of the current tests exercise the spawn path, which is why this crash was not caught.

Comment thread src/mvnw.js Outdated
{
cwd: home,
stdio: 'inherit',
stdio: ['pipe', 'pipe', 'inherit'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

['pipe', 'pipe', 'inherit'] means stdin=pipe, stdout=pipe, stderr=inherit. With stderr inherited, child.stderr is null, which makes the result.stderr.on(...) handler below throw. Two separate problems here:

  • To pipe both stdout and stderr (so you can prefix them), use ['inherit', 'pipe', 'pipe'] and attach handlers to both.
  • Changing stdin from the previous inherit to pipe also detaches the child from the terminal, which can break interactive prompts.

Comment thread src/mvnw.js
}
}
});
result.stderr.on('data', (chunk) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crash site. Because stderr is inherited above, result.stderr is null, so this line throws TypeError: Cannot read properties of null (reading 'on') synchronously, before Maven runs. Verified with mvnw(['--version']) on this branch:

TypeError: Cannot read properties of null (reading 'on')
    at src/mvnw.js:127:19

Either pipe stderr in the stdio array, or drop this handler if stderr is meant to stay inherited.

Comment thread src/mvnw.js
shell: shell(),
}
);
result.stdout.on('data', (chunk) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues with the line-by-line reformatting:

  • line.trim() strips Maven's indentation and collapses whitespace, so structured output (e.g. nested reactor logs) is mangled.
  • A data chunk is not guaranteed to align to line boundaries — a chunk can split a line mid-way, so split(' ') per chunk will timestamp partial lines and concatenate them incorrectly. Buffer until a newline (e.g. readline.createInterface) if you keep this approach.

@nacNAC333

Copy link
Copy Markdown
Contributor Author

@yegor256 Test added — prefixes mvnw output lines with [HH:MM:SS] timestamp captures stdout from mvnw and verifies the [HH:MM:SS] prefix appears on piped output lines. Rebased on latest master, all 6 mvnw tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add timestamps for maven logs

3 participants