Skip to content

Commit e9e6920

Browse files
authored
Merge pull request #2692 from contentstack/v1-back-merge
V1 back merge
2 parents f408af3 + 2a0d3d0 commit e9e6920

5 files changed

Lines changed: 709 additions & 887 deletions

File tree

.talismanrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
fileignoreconfig:
22

33
- filename: pnpm-lock.yaml
4-
checksum: 3d5920821aca485d93dc90dc2006bb81b077344b5f5fd6487002d8b4222cff09
4+
checksum: 98cc0f62b09ea6768f3a20152860a327722a92efaa372acfc7d37bdd2afd014e
5+
- filename: packages/contentstack/README.md
6+
checksum: df0892cbcf3f04972161b30a1a0ef8844a2682ce8a3270f2911909e7789ad8d7
7+
- filename: packages/contentstack-utilities/src/logger/logger.ts
8+
checksum: 8c960b88f59f2efd233e7e00fb69dfb90e6eccf52e7253d144d4e20ff72a6906
59
version: '1.0'

packages/contentstack-auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-auth/2.0.0-beta.17 darwin-arm64 node-v24.18.0
21+
@contentstack/cli-auth/2.0.0-beta.17 darwin-arm64 node-v22.13.1
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-config/2.0.0-beta.15 darwin-arm64 node-v24.18.0
21+
@contentstack/cli-config/2.0.0-beta.15 darwin-arm64 node-v22.13.1
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-utilities/src/logger/logger.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class Logger {
6363
winston.format.printf((info) => {
6464
// Apply minimal redaction for files (debugging info preserved)
6565
const redactedInfo = this.redact(info, false);
66-
return JSON.stringify(redactedInfo);
66+
return this.safeStringify(redactedInfo);
6767
}),
6868
),
6969
}),
@@ -75,7 +75,7 @@ export default class Logger {
7575
const logConfig = configHandler.get('log') || {};
7676
const currentModule = logConfig.progressSupportedModule;
7777
const hasProgressSupport = currentModule && PROGRESS_SUPPORTED_MODULES.includes(currentModule);
78-
78+
7979
if (hasProgressSupport) {
8080
// Plugin has progress bars - respect user's explicit setting, or default to false (show progress bars)
8181
showConsoleLogs = logConfig.showConsoleLogs ?? false;
@@ -146,6 +146,26 @@ export default class Logger {
146146
}
147147
}
148148

149+
/**
150+
* Stringifies a log entry without throwing on circular references.
151+
* `redact()` can fall back to the original (still-circular) object when
152+
* cloning fails, so this must never assume the input is cycle-free.
153+
*/
154+
private safeStringify(value: any): string {
155+
const seen = new WeakSet();
156+
try {
157+
return JSON.stringify(value, (_key, val) => {
158+
if (typeof val === 'object' && val !== null) {
159+
if (seen.has(val)) return '[Circular]';
160+
seen.add(val);
161+
}
162+
return val;
163+
});
164+
} catch {
165+
return JSON.stringify({ level: value?.level, message: value?.message ?? '[Unserializable log entry]' });
166+
}
167+
}
168+
149169
private shouldLog(level: LogType, target: 'console' | 'file'): boolean {
150170
// If console logging is disabled, don't log to console
151171
if (target === 'console' && this.config.consoleLoggingEnabled === false) {
@@ -215,9 +235,12 @@ export default class Logger {
215235
this.loggers.error.error(logPayload);
216236
}
217237

218-
// For console, use debug level if hidden, otherwise error level
238+
// For console, use debug level if hidden, otherwise error level. Each level's
239+
// winston logger instance bundles both the file and console transports, so only
240+
// write again here when the target differs from the one already written above —
241+
// otherwise this would duplicate both the console line and the file entry.
219242
const consoleLevel: LogType = params.hidden ? 'debug' : 'error';
220-
if (this.shouldLog(consoleLevel, 'console')) {
243+
if (consoleLevel !== 'error' && this.shouldLog(consoleLevel, 'console')) {
221244
this.loggers[consoleLevel].error(logPayload);
222245
}
223246
}

0 commit comments

Comments
 (0)