feat(logger): add structured logging with configurable levels and formats#94
Merged
Merged
Conversation
- Add missing "peer": true annotations to @babel/eslint-parser, @types/node, acorn, browserslist, eslint-visitor-keys, and react entries after post-merge npm install
…mats - Add log levels (error/warn/info/debug) with numeric priority hierarchy - Add log formats: text (coloured), json (NDJSON), silent (errors-only) - Add colorize modes: auto (TTY detection), always, never - Route all logs to stderr by default; stdout reserved for program output - Add configure() for runtime reconfiguration from CLI flags - Read COPYTREE_LOG_LEVEL and COPYTREE_LOG_FORMAT directly from process.env - Add --log-level, --log-format, --no-color flags to copytree CLI - Force destination=stderr in stream mode to keep stdout clean - Use InvalidArgumentError for CLI option validation (not process.exit) - Add logging defaults in config/logging.js and schema/schema.json - Replace custom _stripAnsi with strip-ansi package (with string guards) - Add safe JSON serialization for circular refs, BigInt, and Symbol - Route Stage.log() through logger (info→debug for backward compat) - Replace console.warn in Pipeline with context.logger for consistency - Add 27 unit tests for Logger via dedicated loggerUnitProject in Jest - Suppress log noise in E2E tests via COPYTREE_LOG_LEVEL=error env var
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements structured, configurable logging for the CopyTree CLI, replacing the legacy binary
silent/debugmodel with a full level hierarchy, multiple output formats, and runtime reconfiguration from CLI flags.Closes #30
Changes Made
Logger core (
src/utils/logger.js)error(0) < warn(1) < success(2) = info(2) < debug(3)text(coloured terminal),json(NDJSON to stderr),silent(errors only)auto(TTY detection),always,neverstderrby default; stdout is reserved for program outputconfigure()for runtime reconfiguration from CLI flagsCOPYTREE_LOG_LEVELandCOPYTREE_LOG_FORMATdirectly fromprocess.env_stripAnsiwith thestrip-ansipackage (with string guards)CLI (
bin/copytree.js)--log-level <error|warn|info|debug>flag (default:info)--log-format <text|json|silent>flag (default:text)--no-colorflag to disable ANSI codesInvalidArgumentErrorfor option validation (proper Commander.js pattern)Config (
config/logging.js,config/schema.json)logging.*config section with defaults for level, format, colorize, timestamp, destinationPipeline/Stage integration
Stage.log()now routes through the logger (mapsinfo→logger.debug()for backward compat — stage progress was previously silent by default)Pipeline.jsusesthis.context.loggerconsistently (replacedconsole.warnand a straydefaultLogger.warn)destination: 'stderr'to keep stdout clean for piped outputTests
Loggerclass intests/unit/utils/logger.test.jsloggerUnitProjectinjest.config.jsthat tests the real logger without mocking itCOPYTREE_LOG_LEVEL=errorso golden file assertions remain clean