Skip to content

fix(utilities): single session log folder per run via cache in getSessionLogPath#2442

Open
cs-raj wants to merge 1 commit intov2-devfrom
fix/DX-4903
Open

fix(utilities): single session log folder per run via cache in getSessionLogPath#2442
cs-raj wants to merge 1 commit intov2-devfrom
fix/DX-4903

Conversation

@cs-raj
Copy link
Contributor

@cs-raj cs-raj commented Mar 3, 2026

Summary

Fixes multiple log folders being created for a single export/import/clone run by caching the session log path for the process. One CLI run now produces one session folder under the configured log path.

Problem

  • getSessionLogPath() was called many times per run (Logger constructor ×5, export/import command at end, completeProgressWithMessage per module).
  • Each call used new Date() for the folder name (command-YYYYMMDD-HHMMSS-sessionId), so different timestamps created different folders.
  • Users saw several session folders (e.g. under log.path/2026-03-02/) for one command, with logs only in the first folder.

Solution

  • Cache: In session-path.ts, cache the computed session path in a module-level variable. The first call creates the folder and session.json and caches the path; subsequent calls in the same process return the cached path.
  • Tests: Export clearSessionLogPathCache() and call it in beforeEach for the "Session Log Path" and "Session Metadata" tests so each test gets a fresh path and assertions still pass.

Changes

File Change
cli/packages/contentstack-utilities/src/logger/session-path.ts Add cachedSessionPath and early return when set; set cache before return; add and export clearSessionLogPathCache().

Behavior

  • Export/import/clone: One run → one session folder; all log levels and the final “log stored at” message use the same path.
  • Clone (export then import): Same process, same cached path → one folder for the whole clone run.
  • Tests: Clearing the cache per test keeps existing expectations valid; Session Log Path and Session Metadata tests pass.

Testing

  • pnpm test in cli/packages/contentstack-utilities: Session Log Path and Session Metadata (session.json) tests pass.
  • Manual: Run cm:stacks:export with a custom log path; confirm a single session folder is created per run.

@cs-raj cs-raj requested a review from a team as a code owner March 3, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant