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

Expose the logging functions to client-side extensions and automatically account for the value of isDebug #1895

Merged

Conversation

ShyamGadde
Copy link
Contributor

@ShyamGadde ShyamGadde commented Feb 28, 2025

Summary

Fixes #1886

Relevant technical choices

  • Introduced a logger object that encapsulates log, info, warn, and error methods.
  • The logging functions automatically respect the value of isDebug coming from WP_DEBUG in PHP.
  • Exposed logging functions to client-side extensions' initialize() and finalize() functions.
  • Errors (error()) always log regardless of isDebug, since most existing calls didn't check for it.

…lly account for the value of isDebug

Signed-off-by: Shyamsundar Gadde <[email protected]>
Comment on lines 112 to 115
error( ...message ) {
// eslint-disable-next-line no-console
console.error( this.prefix, ...message );
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note about error logging: I noticed that in 5 out of 7 usages, the error function was called without checking isDebug first. It seemed intentional that errors should always be shown, so I've maintained this behavior in the logger implementation. The remaining two cases still explicitly check isDebug before calling error(). Let me know if we should standardize this behavior differently.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, good call. This probably makes sense to log out even if not isDebug.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Feb 28, 2025
@ShyamGadde ShyamGadde marked this pull request as ready for review February 28, 2025 10:41
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ShyamGadde <[email protected]>
Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Looks good!

image

If Embed Optimizer and Image Prioritizer are updated without Optimization Detective:

image

Where the log entries from Embed Optimizer and Image Prioritizer lack the prefixes as expected as a fallback for Optimization Detective not being updated yet.

@westonruter westonruter added [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Plugin] Image Prioritizer Issues for the Image Prioritizer plugin (dependent on Optimization Detective) labels Mar 3, 2025
@westonruter westonruter merged commit 5f47f0a into WordPress:trunk Mar 3, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Plugin] Image Prioritizer Issues for the Image Prioritizer plugin (dependent on Optimization Detective) [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export console logging functions to extensions
2 participants