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

Repo: Set up unique loggers per-file #5872

Open
JoshuaKGoldberg opened this issue Oct 24, 2022 · 1 comment
Open

Repo: Set up unique loggers per-file #5872

JoshuaKGoldberg opened this issue Oct 24, 2022 · 1 comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue 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 maintainers 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 maintainers to take a look labels Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
Development

No branches or pull requests

2 participants