Reporting and logging
Reporting and logging give compiler and tooling users two views of Panda activity. The reporter turns source analysis into token and recipe usage data. The logger turns build progress, timing, warnings, and errors into filtered console or file feedback.
Diagnostic roles
The reporter answers what the codebase uses. The logger answers what the tool is doing and whether an operation needs attention. Together they support both planned audits, such as finding unused design tokens, and live operations, such as watching a build or tracing a parse failure.
| Diagnostic | Main question | Consumer-facing result |
|---|---|---|
| Usage report | Which design tokens and recipes are used? | Structured data and formatted summaries |
| Operational log | What is the compiler or tool doing now? | Filtered terminal messages or JSON log entries |
| Timing log | How long did a selected operation take? | An info or debug message with elapsed time |
| Error report | What failed and where should investigation start? | Context and message at error level, with a stack at debug level |
Reporter
The Reporter in packages/…/reporter.ts is the analysis service for source-level design-system use. It gets the project files, parses them, classifies the discovered properties and components, and keeps the resulting analysis available to later report views.
The reporter does not itself decide how a user sees the result. It exposes a shared analysis model, then derives focused views for tokens and recipes. This separation lets the CLI and other tooling use the same findings without repeating source analysis.
References: packages/…/reporter.ts• L9-18 packages/…/reporter.ts• L32-40 packages/…/reporter.ts• L62-85
Token usage reports
The token report shows how configured token categories are used across source files. It separates known token use from hardcoded values and summarizes coverage so an engineer can see use, unused capacity, common names, and the files involved.
Each category summary includes the configured token count, used count, percent used, hardcoded count, file count, and a short list of the most used token names. Detailed entries also retain the source path and location when the analysis can provide one.
References: packages/…/reporter-token.ts• L14-44 packages/…/reporter-token.ts• L46-91 packages/…/reporter-token.ts• L93-143
Recipe usage reports
The recipe report shows which configured recipe variants and combinations appear in source code. It also separates use through JSX from use through functions, which helps explain how the recipe API is used in the project.
The report compares observed combinations with the combinations allowed by the recipe configuration. It therefore supports cleanup and review by showing both used combinations and the remaining possible combinations.
References: packages/…/reporter-recipe.ts• L4-16 packages/…/reporter-recipe.ts• L18-40 packages/…/reporter-recipe.ts• L47-97
Report formats
The report formatter turns token and recipe summaries into output suited to a person or another tool. Supported formats are JSON, Markdown, CSV, plain text, and terminal tables. The CLI uses tables by default while JSON supports saved reports and machine reads.
The formatter presents the same analysis in each format. It does not change the findings, so a consumer can choose an output form without changing the meaning of the report.
References: packages/…/report-format.ts• L7-17 packages/…/report-format.ts• L17-53 packages/…/report-format.ts• L55-93
Logger
The logger in packages/…/create-logger.ts is the shared operational feedback service. It labels messages by level and type, filters them for the current run, writes suitable entries to the console, and can pass the same entries to another sink.
The default logger reads PANDA_DEBUG. A debug setting enables more detail and can also select message types through a filter. The logger keeps the level model simple: debug is most detailed, then info, warn, error, and silent suppresses normal output.
References: packages/…/create-logger.ts• L5-24 packages/…/create-logger.ts• L26-44 packages/…/create-logger.ts• L119-125 packages/…/index.ts• L6-11
Log levels and types
Every normal log call has a level and a type. The level controls how much output is shown. The type groups messages by area, such as analysis, file extraction, CSS output, or process handling, so a debug session can focus on one area instead of enabling all messages.
The logger also supports unclassified output through log, direct structured display through print, and a callback through onLog. These paths serve different needs: human guidance, deep object inspection, and forwarding to a durable or external sink.
References: packages/…/logger.ts• L1-27 packages/…/create-logger.ts• L26-44 packages/…/create-logger.ts• L63-84 packages/…/create-logger.ts• L89-116
Timing and caught errors
Timing helpers measure a named operation and emit its elapsed time at info or debug level. Compiler paths use them around parsing, extraction, initialization, and output work so a user can see progress without a separate tracing system.
Caught errors produce a short contextual message at error level. When the value is an Error, the full stack is sent at debug level. This keeps normal output useful while preserving a path to deeper diagnosis.
References: packages/…/create-logger.ts• L46-61 packages/…/logger.ts• L17-25 packages/…/create-context.ts• L66-82 packages/…/node-runtime.ts• L83-91
Compiler feedback flow
Compiler and tooling consumers use the same analysis and logger services but surface them in different ways. The CLI gives people immediate formatted output or a saved JSON snapshot. MCP gives an external tool structured usage data. The node runtime can also forward operational entries to a newline-delimited log file.
This diagram shows how source analysis and operational events reach human and machine consumers.
flowchart TD
A[Source files and Panda config] --> B[Reporter]
B --> C[Token and recipe findings]
C --> D[CLI formatted output]
C --> E[CLI JSON report]
C --> F[MCP usage response]
G[Compiler and tooling events] --> H[Logger]
H --> I[Filtered terminal output]
H --> J[Log callback]
J --> K[JSON lines log file]
References: packages/…/analyze.ts• L5-28 packages/…/cli-main.ts• L388-438 packages/…/server.ts• L134-164 packages/…/logstream.ts• L10-39
CLI analysis
The analyze command in packages/…/cli-main.ts runs the reporter over the selected source scope. It can limit the result to tokens or recipes, print formatted summaries, or write the complete analysis report as JSON.
The --silent option changes the logger level for runs where the report itself is the only desired output. If the selected configuration has no tokens or recipes, the command states that instead of producing an empty-looking section.
References: packages/…/cli-main.ts• L388-417 packages/…/cli-main.ts• L421-438
MCP usage reporting
The MCP get_usage_report tool exposes the same token and recipe findings to an external tool caller. Its scope selects tokens, recipes, or both, and its response contains structured data rather than terminal formatting.
This interface is useful when an agent or editor needs to inspect design-system use without parsing CLI text. It still uses the same analysis source, so the scope choice changes the response shape but not the underlying rules.
References: packages/…/server.ts• L134-164
Log file streaming
The node log stream connects the logger callback to a file. It resolves the path from the working directory, creates missing parent folders, and appends one JSON log entry per line. This preserves timestamps, types, levels, and messages for later review.
The stream closes on explicit disposal or process interruption. Console filtering and file capture are separate concerns: an entry can be forwarded to the file even when normal terminal output does not show it.
References: packages/…/logstream.ts• L5-25 packages/…/logstream.ts• L28-45
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the reporter's shared analysis model aligned with the token and recipe projections. A change to classified item types can affect both reports.
- Keep report format names aligned across the formatter, CLI options, and any consumers that expect structured JSON.
- Keep logger level and filter behavior aligned with
PANDA_DEBUG, silent CLI runs, and theonLogfile sink. - Preserve the log entry fields used by JSON-lines consumers when changing console formatting.
- Keep MCP usage scope values aligned with the token and recipe branches in
get_usage_report.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A source file cannot be parsed | Its result is absent from analysis and its usage is not represented | The node context logs the file path and error context, then continues the managed parse path |
PANDA_DEBUG or a type filter is too broad | Terminal output becomes noisy and hides the useful event | Use the narrowest message type filter that answers the question |
| A report is written through a format that does not preserve structured data | A downstream tool cannot reliably inspect the findings | Use the JSON report for machine reads and formatted modes for human output |
| A log file path cannot be prepared or written | Operational history is not available in the file sink | Check the resolved path and the process permissions before relying on file capture |
| A configuration has no tokens or recipes in the selected scope | The related report has no findings | Treat the CLI's explicit “No tokens found” or “No config recipes found” message as a valid result |
Key files
| File | Why to read it |
|---|---|
| packages/…/reporter.ts | Defines the shared analysis lifecycle and the token and recipe report entry points. |
| packages/…/reporter-token.ts | Explains token coverage, hardcoded values, file use, and summary data. |
| packages/…/reporter-recipe.ts | Explains recipe combinations and JSX versus function use. |
| packages/…/report-format.ts | Shows how the same findings become human or machine output. |
| packages/…/create-logger.ts | Defines levels, filters, timing, error capture, and log forwarding. |
| packages/…/analyze.ts | Connects the reporter to the node-facing analysis API. |
| packages/…/cli-main.ts | Shows how command users select, print, or save analysis results. |
| packages/…/server.ts | Shows how tooling consumers receive structured usage reports. |
| packages/…/logstream.ts | Shows how operational log entries reach a JSON-lines file. |