Skip to content

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

Merged
westonruter merged 11 commits intoWordPress:trunkfrom
ShyamGadde:try/export-logging-func-to-ext
Mar 3, 2025
Merged

Expose the logging functions to client-side extensions and automatically account for the value of isDebug#1895
westonruter merged 11 commits intoWordPress:trunkfrom
ShyamGadde:try/export-logging-func-to-ext

Conversation

@ShyamGadde
Copy link
Copy Markdown
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 <shyamsundar.gadde@rtcamp.com>
Comment thread plugins/optimization-detective/detect.js Outdated
Comment on lines +112 to +115
error( ...message ) {
// eslint-disable-next-line no-console
console.error( this.prefix, ...message );
},
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread plugins/optimization-detective/types.ts Outdated
Comment thread plugins/optimization-detective/types.ts
Comment thread plugins/optimization-detective/detect.js Outdated
Comment thread plugins/optimization-detective/detect.js Outdated
Comment thread plugins/optimization-detective/detect.js
Comment thread plugins/embed-optimizer/detect.js Outdated
Comment thread plugins/embed-optimizer/detect.js Outdated
Comment thread plugins/image-prioritizer/detect.js Outdated
Comment thread plugins/embed-optimizer/detect.js Outdated
Comment thread plugins/image-prioritizer/detect.js Outdated
@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 and others added 7 commits February 28, 2025 15:04
Co-authored-by: Weston Ruter <westonruter@google.com>
Co-authored-by: Weston Ruter <westonruter@google.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
@ShyamGadde ShyamGadde marked this pull request as ready for review February 28, 2025 10:41
@github-actions
Copy link
Copy Markdown

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 <shyamgadde@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

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

Comment thread plugins/image-prioritizer/detect.js Outdated
Comment thread plugins/optimization-detective/types.ts Outdated
Comment thread plugins/optimization-detective/detect.js Outdated
Comment thread plugins/optimization-detective/detect.js Outdated
ShyamGadde and others added 3 commits March 3, 2025 11:37
Co-authored-by: Weston Ruter <westonruter@google.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Copy link
Copy Markdown
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
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