Skip to content

test(framework): fix StdoutLogger tests to handle timestamp prefix - #7621

Merged
limingxinleo merged 7 commits into
hyperf:3.2from
huangdijia:test/fix-stdout-logger-timestamp-tests
Dec 4, 2025
Merged

limingxinleo merged 7 commits into
hyperf:3.2from
huangdijia:test/fix-stdout-logger-timestamp-tests

Conversation

@huangdijia

@huangdijia huangdijia commented Nov 13, 2025 •

Copy link
Copy Markdown
Member

Summary

Fixed StdoutLoggerTest to properly handle the new timestamp format that was recently added to StdoutLogger. The logger now outputs timestamps in the format [YYYY-MM-DD HH:MM:SS.mmm] before each log message, but the tests were not updated to account for this change.

Changes

  • Updated getLogger() method to strip timestamp prefix before comparing expected vs actual output
  • Fixed expected output format spacing (changed from single space </> to double space </> )
  • All 4 tests now pass successfully

Test Results

PHPUnit 11.5.43 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 00:00.025, Memory: 16.00 MB

OK (4 tests, 4 assertions)

Test Plan

  • Run composer test -- src/framework/tests/StdoutLoggerTest.php
  • All tests pass (testLog, testFixedErrorContextCount, testLogComplexityContext, testLogThrowable)
  • Verified regex pattern correctly strips timestamp prefix

Updated StdoutLoggerTest to properly handle the new timestamp format
introduced in StdoutLogger. The logger now outputs timestamps in the
format [YYYY-MM-DD HH:MM:SS-mmm] before each log message.

Changes:
- Updated test assertions to strip timestamp prefix before comparison
- Fixed expected output format spacing (single to double space)
- All tests now pass with the new timestamp feature

Fixes test failures in StdoutLoggerTest::testLog,
testFixedErrorContextCount, and testLogComplexityContext
Fixed StdoutLogger to properly handle spacing when tags are present or absent.
Updated tests to strip timestamp prefix before comparison.

Changes to StdoutLogger.php:
- Improved tag spacing logic to avoid double spaces when no tags present
- Tags string now conditionally adds leading space only when tags exist
- Format: [timestamp] <level>[LEVEL]</> message (no tags)
- Format: [timestamp] <level>[LEVEL]</> [tag] message (with tags)

Changes to StdoutLoggerTest.php:
- Added timestamp stripping in test assertions using regex
- Tests now properly handle dynamic timestamps in log output
- All 4 tests pass successfully

Fixes spacing issues in log output formatting.
@tw2066

tw2066 commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

@huangdijia 大佬 .v 是不是更好

image

Comment thread src/framework/src/Logger/StdoutLogger.php Outdated
Comment thread src/framework/tests/StdoutLoggerTest.php Outdated
@huangdijia

Copy link
Copy Markdown
Member Author

@huangdijia 大佬 .v 是不是更好

image

调整了

Copilot AI review requested due to automatic review settings December 4, 2025 03:11

Copilot AI 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.

Pull request overview

This PR fixes the StdoutLoggerTest to properly handle the new timestamp prefix feature that was added to StdoutLogger. The logger now prepends timestamps in the format [YYYY-MM-DD HH:MM:SS.mmm] to all log messages, and the tests needed to be updated to strip this prefix before comparing expected vs actual output.

Key changes:

  • Updated test helper method to strip timestamp prefix using regex before assertions
  • Added timestamp formatting to the logger's message output
  • Updated CHANGELOG to document the new timestamp feature

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/framework/tests/StdoutLoggerTest.php Modified getLogger() method to strip timestamp prefix from messages before assertion comparison
src/framework/src/Logger/StdoutLogger.php Added timestamp prefix to log message format and refactored message formatting logic
CHANGELOG-3.2.md Documented the addition of timestamp prefix feature to StdoutLogger

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$output = Mockery::mock(ConsoleOutput::class);
$output->shouldReceive('writeln')->with(Mockery::any())->once()->andReturnUsing(function ($message) use ($expected) {
$this->assertSame($expected, $message);
// Strip the timestamp prefix [YYYY-MM-DD HH:MM:SS-mmm] before comparing

Copilot AI Dec 4, 2025

Copy link

Choose a reason for hiding this comment

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

The comment says the format is [YYYY-MM-DD HH:MM:SS-mmm] but the actual format uses a dot (.) before milliseconds, not a hyphen (-). The comment should be updated to match the actual format: [YYYY-MM-DD HH:MM:SS.mmm].

Suggested change
// Strip the timestamp prefix [YYYY-MM-DD HH:MM:SS-mmm] before comparing
// Strip the timestamp prefix [YYYY-MM-DD HH:MM:SS.mmm] before comparing

Copilot uses AI. Check for mistakes.
@limingxinleo
limingxinleo merged commit 99e063a into hyperf:3.2 Dec 4, 2025
79 of 82 checks passed
@huangdijia
huangdijia deleted the test/fix-stdout-logger-timestamp-tests branch December 4, 2025 03:40
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.

4 participants