Skip to content

Repo: Standardize debug namespaces per-file #5872

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.repo maintenancethings to do with maintenance of the repo, and not with code/docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions