Skip to content

Repo: Standardize debug namespaces per-file #5872

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

Closed
JoshuaKGoldberg opened this issue Oct 24, 2022 · 2 comments · Fixed by #10599
Closed

Repo: Standardize debug namespaces per-file #5872

JoshuaKGoldberg opened this issue Oct 24, 2022 · 2 comments · Fixed by #10599
Labels
accepting prs Go ahead, send a pull request that resolves this issue locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. repo maintenance things to do with maintenance of the repo, and not with code/docs

Comments

@JoshuaKGoldberg
Copy link
Member

Suggestion

Splitting out of #5834 (comment):

in an ideal world we'd actually do a unique substring per file to help differentiate where logs are coming from.

eg typescript-eslint:typescript-estree:inferSingleRun, typescript-eslint:typescript-estree:create-program:useProvidedPrograms, etc

this also allows you to easily filter the log lines to specific usecases with env vars like DEBUG=typescript-eslint:typescript-estree:create-program:*

also helpful because debug also colours each string differently IIRC so it's easy to see different sources when parsing logs.

I wonder if we can automate creation of the string via like

const PACKAGE_ROOT = "resolve from disk somehow";

function getLogger(filename: string) {
  const relative = path.relative(PACKAGE_ROOT, filename);
  const parsed = path.parse(relative);
  return debug(`typescript-eslint:${parsed.dir.replace(/\//g, ':')}:${parsed.name}`);
}

// then call this via
const log = getLogger(__filename);

It'd be nifty if we could use a lint rule that enforces such a thing.

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for team members to take a look repo maintenance things to do with maintenance of the repo, and not with code/docs labels Oct 24, 2022
@bradzacher
Copy link
Member

It'd be nifty if we could use a lint rule that enforces such a thing.

Sadly eslint-plugin-debug doesn't exist :(

We could create an internal rule for us to enforce the style, for sure!

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Oct 24, 2022
@JoshuaKGoldberg
Copy link
Member Author

JoshuaKGoldberg commented Jan 3, 2025

I tried out the getLogger(__filename) strategy in #10598.

  • Advantage: it's very convenient to no longer have to manually massage those strings!
  • Disadvantage: the strings are no longer searchable

I think the lint rule will be the way to go. We can have it provide auto-fixes so we don't have to manually type strings out.

@JoshuaKGoldberg JoshuaKGoldberg changed the title Repo: Set up unique loggers per-file Repo: Standardize debug namespaces per-file Jan 3, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jan 21, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
2 participants