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

Revisiting ⁠console.success: A Case for Standardizing Success Logging #243

Open
brandonmcconnell opened this issue Mar 3, 2025 · 3 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@brandonmcconnell
Copy link

brandonmcconnell commented Mar 3, 2025

Problem Statement

Developers currently lack a standardized, semantic method for logging successful operations. While console.error and console.warn provide clear semantic meaning for negative outcomes, there is no equivalent for positive outcomes. This creates an asymmetry in the console API that forces developers to use workarounds like console.log("✅ Success: ...") or custom styling.

Current Landscape Analysis

I'm aware this was previously proposed in #155 and was rejected. The main objections were:

  1. Regular console.log is sufficient for success messages
  2. The spec shouldn't dictate styling for success messages
  3. Custom styling can be implemented by developers

However, I believe there are compelling reasons to reconsider this proposal with a more comprehensive analysis.

Why This Deserves Reconsideration

1. Semantic Consistency

The console API already provides semantic methods for different message types:

  • console.error() - For errors
  • console.warn() - For warnings
  • console.info() - For informational messages
  • console.debug() - For debug messages

Adding console.success() would complete this semantic hierarchy, providing a clear, intention-revealing API for all common logging scenarios.

2. Accessibility Considerations

Success messages are often distinguished only by color (typically green). A semantic console.success method would allow browser devtools to implement accessible indicators beyond just color, improving usability for developers with color vision deficiencies.

Implementation Proposal

I propose adding console.success() with the following characteristics:

  1. Functional Behavior: Identical to console.log() in terms of parameter handling and output
  2. Semantic Meaning: Explicitly indicates a successful operation
  3. Default Styling: Recommended (but not required) to use distinguishable styling from other console methods
  4. Browser Implementation: Browsers would be free to style as appropriate for their devtools
// Example usage
console.success("User registration completed");
console.success("Payment processed", paymentDetails);

Addressing Previous Concerns

  1. "Regular console.log is sufficient": While functionally true, this argument could apply to console.warn and console.info as well, yet those exist because semantic meaning matters.

  2. "We shouldn't dictate styling": This proposal doesn't require specific styling, just as the spec doesn't mandate red for errors. It simply provides the semantic method.

  3. "Developers can implement custom solutions": The same is true for all console methods, yet we standardize them for consistency across environments.

Benefits of Standardization

  1. Consistency: Developers would have a standard way to log success messages
  2. Filtering: Console filters could easily include/exclude success messages
  3. Tooling: DevTools could offer special handling for success messages, as well as error/warn messages
  4. Learning: New developers would have a clear, discoverable API for success logging
@brandonmcconnell brandonmcconnell added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Mar 3, 2025
@brandonmcconnell
Copy link
Author

@domfarolino I'd like to invite you to discuss this proposal as you played a significant role in the progression of the previous proposal — #155

@terinjokes
Copy link
Collaborator

I don't think there's anything that has changed since the previous discussions. The existing methods (including trace omitted above) are not semantic in so much as they are logging levels, with a unleveled "log" for backwards compatibility. Successes would likely be at the informational or lower level.

@brandonmcconnell
Copy link
Author

@terinjokes However, a success message is still more semantic and informative than merely using a log and adding custom styles, not to mention easier to indicate a success message apart from typical logs without having to type out %c and CSS inside your logs.

Currently, it's feasible enough for a library to set up proxy to trigger any time any of the console methods are invoked, and then send the messages attached to those invocations to another source like Rollbar, etc. Having a first-party success method would allow different libs to attach events to that same method for successes without implementing various different success methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

2 participants