Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize log storage #1315

Merged
merged 59 commits into from
Apr 25, 2024
Merged

Centralize log storage #1315

merged 59 commits into from
Apr 25, 2024

Conversation

bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented Apr 24, 2024

What is this PR doing?

It moves away from using the JS logger (console) to the @php-wasm/logger.

What problem is it solving?

It centralizes log collections which will allow us to better utilize logs in the future.

How is the problem addressed?

By replacing console calls with logger calls.

Testing Instructions

  • Checkout this branch
  • Open this blueprint
  • Open the report error modal (menu in upper right corner > Report error)
  • See JS logs in the LOGS textarea

Please review the log messages in this PR and suggest changes (using the GitHub suggest feature) to messages if they could be improved.

@@ -29,7 +29,7 @@ export function ErrorReportModal(props: { blueprint: Blueprint }) {
useEffect(() => {
resetForm();
if (showErrorModal) {
setLogs(logger.getLogs().join(''));
setLogs(logger.getLogs().join('\n'));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ensure log entries are displayed as lines

Comment on lines -14 to -26
it('Event listener should work', () => {
const listener = vi.fn();
collectPhpLogs(logger, php);
addCrashListener(logger, listener);
php.dispatchEvent({
type: 'request.error',
error: new Error('test'),
});
expect(listener).toBeCalledTimes(1);

const logs = logger.getLogs();
expect(logs.length).toBe(1);
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test would require a lot of mocking and it's not that useful, so I removed it.

UniversalPHP,
PHPRequestErrorEvent,
} from '@php-wasm/universal/src/lib/universal-php';
import { UniversalPHP, PHPRequestErrorEvent } from '../../universal';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These imports were causing circular dependency issues, so I added type declarations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not great, not terrible 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can always switch to any 😅

@bgrgicak bgrgicak requested a review from a team April 24, 2024 11:32
@bgrgicak
Copy link
Collaborator Author

@WordPress/playground-maintainers I'm asking for a review early to get your suggestions for log message improvements.

I will work tomorrow on fixing the e2e errors.

@adamziel
Copy link
Collaborator

I'm asking for a review early to get your suggestions for log message improvements.

It seems like this PR is focused on replacing console with logger, let's discuss log messages separately.

Base automatically changed from add/log-methods to trunk April 25, 2024 05:46
@bgrgicak bgrgicak marked this pull request as ready for review April 25, 2024 07:57
@bgrgicak bgrgicak changed the title Update/console to logger Centralize log storage Apr 25, 2024
@bgrgicak bgrgicak merged commit 27fee12 into trunk Apr 25, 2024
5 checks passed
@bgrgicak bgrgicak deleted the update/console-to-logger branch April 25, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants