Skip to content

Add getLoggers() to list loggers in a category tree - #207

Merged
dahlia merged 3 commits into
dahlia:mainfrom
Polqt:feat/get-loggers
Aug 21, 2026
Merged

Add getLoggers() to list loggers in a category tree#207
dahlia merged 3 commits into
dahlia:mainfrom
Polqt:feat/get-loggers

Conversation

@Polqt

@Polqt Polqt commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Closes #62.

Right now there's no way to find out which loggers exist in a running program. If you're building something like a debug panel where users can toggle categories on and off, or you just want to sanity-check what logging is active, you have to already know every category name up front.

This adds getLoggers(), which walks the category tree from a given logger (or the root, by default) and returns every logger in that subtree, including the one you passed in, in depth-first order:

const all = getLoggers();          // the whole tree, from the root down
const mine = getLoggers("my-app"); // "my-app" and its descendants only

It also accepts a Logger, a category string, or a category array, same as getLogger().

One thing worth calling out (this came up in the discussion on #62): it only sees loggers that have actually been created via a getLogger() call somewhere in the program, not every category that's been set up through configure(). If a category is only reached lazily inside a function that hasn't run yet, it won't show up. That's documented in the docstring.

Testing

Added tests in logger.test.ts covering: a fresh/never-touched category, a multi-level subtree in depth-first order, identity with getLogger(), the no-argument default, an untouched descendant being correctly omitted, and dead WeakRef entries being skipped without being pruned from the tree.

Ran the Node test suite locally (pnpm test in packages/logtape) — all passing. I wasn't able to run deno check/deno lint/mise run check in my environment (no deno/mise install available), so it'd be good to have CI confirm those.


AI disclosure: This PR was written with assistance from Claude Code (claude-sonnet-5) — design discussion, implementation, and tests. I reviewed and tested everything locally before submitting. See Assisted-by trailers in the commit.

There's currently no way to find out which loggers exist at runtime,
which makes it hard to build things like a debug panel that lets
users toggle categories on and off, or just to double check what
logging is actually active in an app.

getLoggers() walks the category tree from a given logger (or the
root by default) and returns every logger in that subtree, including
the one you passed in, in depth-first order. It only sees loggers
that have actually been created via getLogger() somewhere, not every
category that's been configured — that limitation is called out in
the docstring.

Closes dahlia#62

Assisted-by: Claude Code:claude-sonnet-5
@dahlia dahlia self-assigned this Aug 21, 2026
@dahlia dahlia added this to the LogTape 2.4 milestone Aug 21, 2026
@dahlia dahlia added the enhancement New feature or request label Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.93%. Comparing base (602e54c) to head (c2ff7e8).
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/logtape/src/logger.ts 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #207      +/-   ##
==========================================
- Coverage   86.00%   85.93%   -0.08%     
==========================================
  Files          70       71       +1     
  Lines       12980    13015      +35     
  Branches     2925     2939      +14     
==========================================
+ Hits        11164    11184      +20     
- Misses       1288     1297       +9     
- Partials      528      534       +6     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dahlia dahlia left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for your contribution.

Could you run mise run fmt for formatting?

Also, it would be great if this feature is documented in the VitePress docs (docs/).

Comment thread changes.d/logtape/get-loggers.md Outdated
Adds a "Listing loggers" section to docs/manual/categories.md, and
adds the PR number and contributor credit to the changelog fragment,
per review feedback on dahlia#207.

Assisted-by: Claude Code:claude-sonnet-5
@Polqt

Polqt commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback!

Pushed as 490bdfd.

@dahlia dahlia left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The code is still not well-formatted!

Collapse the ternary in collectDescendants() back to one line, per
CI's deno fmt --check failure.

Assisted-by: Claude Code:claude-sonnet-5
@dahlia
dahlia merged commit 5735408 into dahlia:main Aug 21, 2026
22 of 26 checks passed
@dahlia

dahlia commented Aug 21, 2026

Copy link
Copy Markdown
Owner

This feature will be shipped with the next minor release, LogTape 2.4.0. Meanwhile, you could try v2.4.0-dev.865+57354081, a pre-release build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: is there a way to grab list of all 'registered' categories?

2 participants