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

fix(log): ensure consistent behavior with @std/log #5974

Merged
merged 4 commits into from
Sep 27, 2024
Merged

fix(log): ensure consistent behavior with @std/log #5974

merged 4 commits into from
Sep 27, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Sep 13, 2024

Fixes #5972

@iuioiua iuioiua requested a review from kt3k as a code owner September 13, 2024 01:21
@github-actions github-actions bot added the log label Sep 13, 2024
Copy link
Contributor Author

@iuioiua iuioiua Sep 13, 2024

Choose a reason for hiding this comment

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

This test is failing because debug() doesn't actually print to the console for some reason. Need to figure out why... Any ideas, @kt3k?

Copy link
Member

Choose a reason for hiding this comment

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

I think you need to call setup and override the default log level to DEBUG like the below:

import * as log from "@std/log";
log.setup({
  handlers: {
    default: new log.ConsoleHandler("DEBUG"),
  },  
  loggers: {
    default: {
      level: "DEBUG",
      handlers: ["default"],
    }   
  }
});
log.debug("debug");

The default log level is set to "INFO" here

export const DEFAULT_LEVEL = "INFO";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting we add that to log/debug.ts? What is the expected behavior of the following script?

import { debug } from "@std/log/debug";

debug("Hello, world!");

Copy link
Member

Choose a reason for hiding this comment

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

I think the expected behavior is noop because the default log level is not low enough to log DEBUG log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have one more thing to check to see if that's true. But if it is true, we should remove the function.

Copy link
Member

Choose a reason for hiding this comment

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

It's noop by default, however the behavior can be changed if the user want to see the debug logs. I personally don't think the removal is a good idea.

Copy link
Contributor Author

@iuioiua iuioiua Sep 26, 2024

Choose a reason for hiding this comment

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

Yeah, actually, I'll just document the behavior then.

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.76%. Comparing base (d902c24) to head (15e3d89).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5974   +/-   ##
=======================================
  Coverage   96.76%   96.76%           
=======================================
  Files         508      508           
  Lines       39101    39106    +5     
  Branches     5786     5786           
=======================================
+ Hits        37836    37841    +5     
  Misses       1225     1225           
  Partials       40       40           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iuioiua
Copy link
Contributor Author

iuioiua commented Sep 26, 2024

@kt3k PTAL

@iuioiua iuioiua enabled auto-merge (squash) September 26, 2024 23:16
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@iuioiua iuioiua merged commit 2774a07 into main Sep 27, 2024
16 checks passed
@iuioiua iuioiua deleted the fix-log branch September 27, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(log): warn() and others behave different depending on import
2 participants