-
Notifications
You must be signed in to change notification settings - Fork 983
feat(logging): human-readable console logs and cleaner plugin errors #7293
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
base: newarchitecture
Are you sure you want to change the base?
feat(logging): human-readable console logs and cleaner plugin errors #7293
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
| // Set config.logging.prettyPrint = false for JSON output (e.g., for log aggregation) | ||
| this.#prettyPrint = this.#prefs.prettyPrint !== false; | ||
|
|
||
| // Initialize OpenTelemetry metrics if available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this but please dont enable this by default.
This is only good for dev envs, since most of our logs are now json ( the ones that are not will be converted ) They will be human readable for prod using grafana or other tools.
The other issue with pretty is it works with event emitter and since countly has huge number of subloggers (plugins,modules each have their own) This can cause memory leaks and similar issues
ref: pinojs/pino-pretty#387
ref: pinojs/pino#144
Lets keep this but not enable by default, or by default when NODE_ENV === development or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| "@types/underscore": "^1.13.0", | ||
| "@typescript-eslint/eslint-plugin": "^8.54.0", | ||
| "@typescript-eslint/parser": "^8.54.0", | ||
| "debug": "^4.4.3", |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug is required at runtime from plugins/pluginManager.ts, but it's being added under devDependencies. If Countly is installed with npm ci --omit=dev / production-only installs, require('debug') will throw and the plugin manager will crash on startup. Move debug to dependencies or make the import optional (fallback to a no-op logger).
| const spawn: typeof cp.spawn = cp.spawn; | ||
| const configextender: ConfigExtenderFn = require('../api/configextender'); | ||
|
|
||
| const d = debug('countly:pluginManager'); |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description says verbose plugin load errors are available via DEBUG=countly:plugins, but the code uses debug('countly:pluginManager'). Either switch the namespace to match the documented env var, or update the PR/docs so developers know which DEBUG value to set.
api/utils/log.js
Outdated
| // Pretty-print enabled by default for human-readable console output | ||
| // Set config.logging.prettyPrint = false for JSON output (e.g., for log aggregation) | ||
| this.#prettyPrint = this.#prefs.prettyPrint !== false; |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaulting prettyPrint to enabled (prettyPrint !== false) is a behavior change from the existing config docs/sample (api/config.sample.js documents [prettyPrint=false]). This can surprise production/log aggregation setups if they haven't explicitly set the flag. Consider enabling pretty printing only when process.stdout.isTTY / non-production, and/or update the sample config/docs to reflect the new default clearly.
- Enable pretty-print by default for better developer experience - Use pino-pretty as direct stream instead of pino.transport() - Simplify timestamp to show time only (HH:MM:ss.l) - Add graceful fallback when pino-pretty is not available Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add debug package for conditional verbose logging - Show clean one-line error on plugin load failure - Full stack trace only visible with DEBUG=countly:plugins Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pretty-print for human-readable output in terminals and CI, JSON for log aggregation in production (Docker/PM2/pipes). - TTY detected → pretty format - CI env var set → pretty format - Otherwise → JSON for collectors (Loki, ELK, etc.) Explicit config still overrides: `logging.prettyPrint: true|false` Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a800b57 to
bbe1fd5
Compare
Summary
This PR improves the developer experience when working with Countly by making console logs more human-readable during development.
Changes
Human-readable console logs
pino-prettyby default for console outputHH:MM:ss.l) instead of full datetimeconfig.logging.prettyPrint = falsefor production/log aggregationCleaner plugin load errors
DEBUG=countly:pluginsenvironment variableWhy these changes?
Console readability: The default JSON output from Pino is optimized for machine parsing and log aggregation, but it's difficult for developers to scan during local development. Pretty-printed logs with simplified timestamps make it much easier to follow what's happening when debugging.
Debug-js for verbose errors: When a plugin fails to load due to a missing dependency, the full stack trace with "Require stack" clutters the console and obscures other important startup messages. Using
debug-jsfollows the Node.js ecosystem convention where verbose output is opt-in via theDEBUGenvironment variable, keeping the default output clean while preserving access to detailed diagnostics when needed.Test plan
DEBUG=countly:pluginsshows full stack tracesconfig.logging.prettyPrint = falsedisables pretty-printing🤖 Generated with Claude Code
Example of console output from starting the ingestor process
Example of console output when starting api without
DEBUGset