Skip to content

Commit

Permalink
fix(cli): introduce log level trace (#5656)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Jan 19, 2025
1 parent 52066d6 commit b623a66
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 12 deletions.
3 changes: 0 additions & 3 deletions fern/pages/changelogs/cli/2025-01-19.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
## 0.50.10
**`(fix):`** An addition to the broken link checker to further reduce false positives.

## 0.50.9
**`(fix):`** The Fern CLI no longer logs the full API request when finishing docs registration,
reducing unnecessary log output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FernGeneratorExec, GeneratorNotificationService } from "./GeneratorNoti
import { getSdkVersion } from "./utils";

const LOG_LEVEL_CONVERSIONS: Record<LogLevel, FernGeneratorExec.logging.LogLevel> = {
[LogLevel.Trace]: FernGeneratorExec.logging.LogLevel.Debug,
[LogLevel.Debug]: FernGeneratorExec.logging.LogLevel.Debug,
[LogLevel.Info]: FernGeneratorExec.logging.LogLevel.Info,
[LogLevel.Warn]: FernGeneratorExec.logging.LogLevel.Warn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { writeGitHubWorkflows } from "./writeGitHubWorkflows";
const OUTPUT_ZIP_FILENAME = "output.zip";

const LOG_LEVEL_CONVERSIONS: Record<LogLevel, FernGeneratorExec.logging.LogLevel> = {
[LogLevel.Trace]: FernGeneratorExec.logging.LogLevel.Debug,
[LogLevel.Debug]: FernGeneratorExec.logging.LogLevel.Debug,
[LogLevel.Info]: FernGeneratorExec.logging.LogLevel.Info,
[LogLevel.Warn]: FernGeneratorExec.logging.LogLevel.Warn,
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/cli/src/cli-context/TtyAwareLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function formatLog(log: Log, { includeDebugInfo }: { includeDebugInfo: boolean }
case LogLevel.Warn:
return chalk.hex("FFA500")(content);
case LogLevel.Debug:
case LogLevel.Trace:
case LogLevel.Info:
return content;
}
Expand All @@ -188,6 +189,8 @@ function getLogLevelAsString(logLevel: LogLevel) {
return "WARN";
case LogLevel.Error:
return "ERROR";
case LogLevel.Trace:
return "TRACE";
default:
assertNever(logLevel);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function runCli() {

if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) {
const { setGlobalDispatcher, Agent } = await import("undici");
setGlobalDispatcher(new Agent({ connect: { timeout: 5_000 } }));
setGlobalDispatcher(new Agent({ connect: { timeout: 5_000 }, bodyTimeout: 0, headersTimeout: 6_000 }));
}

// eslint-disable-next-line @typescript-eslint/no-misused-promises
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
- changelogEntry:
- summary: |
The CLI now supports a `--log-level trace` option to filter out noise from the
debug log level.
type: fix
irVersion: 55
version: 0.50.11

- changelogEntry:
- summary:
An addition to the broken link checker to further reduce false positives.
type: fix
irVersion: 55
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/docs-resolver/src/ApiDefinitionHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class ApiDefinitionHolder {
});

locators.forEach((locator) => {
this.context?.logger.debug(`Registering endpoint locator: ${locator}`);
this.context?.logger.trace(`Registering endpoint locator: ${locator}`);
this.#endpointsByLocator.set(locator, endpoint);
});
});
Expand Down Expand Up @@ -164,7 +164,7 @@ export class ApiDefinitionHolder {
});

locators.forEach((locator) => {
this.context?.logger.debug(`Registering websocket locator: ${locator}`);
this.context?.logger.trace(`Registering websocket locator: ${locator}`);
this.#webSocketsByLocator.set(locator, webSocket);
});
});
Expand Down Expand Up @@ -199,7 +199,7 @@ export class ApiDefinitionHolder {
const path = packageList.length === 0 ? [ROOT_PACKAGE_ID] : packageList;
const locators = [path.join("."), path.join("/"), `${path.join(".")}.yml`];
locators.forEach((locator) => {
this.context?.logger.debug(`Registering subpackage locator: ${locator}`);
this.context?.logger.trace(`Registering subpackage locator: ${locator}`);
this.#subpackagesByLocator.set(locator, pkg);
});

Expand All @@ -211,7 +211,7 @@ export class ApiDefinitionHolder {
const path = [...packageList, endpoint.id];
const locators = [path.join("."), path.join("/")];
locators.forEach((locator) => {
this.context?.logger.debug(`Registering endpoint locator: ${locator}`);
this.context?.logger.trace(`Registering endpoint locator: ${locator}`);
this.#endpointsByLocator.set(locator, endpoint);
});
});
Expand All @@ -220,7 +220,7 @@ export class ApiDefinitionHolder {
const path = [...packageList, webSocket.id];
const locators = [path.join("."), path.join("/")];
locators.forEach((locator) => {
this.context?.logger.debug(`Registering websocket locator: ${locator}`);
this.context?.logger.trace(`Registering websocket locator: ${locator}`);
this.#webSocketsByLocator.set(locator, webSocket);
});
});
Expand All @@ -229,7 +229,7 @@ export class ApiDefinitionHolder {
const path = [...packageList, webhook.id];
const locators = [path.join("."), path.join("/")];
locators.forEach((locator) => {
this.context?.logger.debug(`Registering webhook locator: ${locator}`);
this.context?.logger.trace(`Registering webhook locator: ${locator}`);
this.#webhooksByLocator.set(locator, webhook);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ export async function publishDocs({
CjsFdrSdk.docs.v1.write.DocsRegistrationId(docsRegistrationId),
{
docsDefinition
},
{
timeoutInSeconds: 600
}
);

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/logger/src/LogLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const LogLevel = {
Debug: "debug",
Info: "info",
Warn: "warn",
Error: "error"
Error: "error",
Trace: "trace"
} as const;

export type LogLevel = Values<typeof LogLevel>;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LogLevel } from "./LogLevel";
export interface Logger {
disable: () => void;
enable: () => void;
trace: (...args: string[]) => void;
debug: (...args: string[]) => void;
info: (...args: string[]) => void;
warn: (...args: string[]) => void;
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/logger/src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function log(level: LogLevel, ...args: string[]): void {

function getConsoleLoggerForLevel(level: LogLevel): (...args: string[]) => void {
switch (level) {
case LogLevel.Trace:
// eslint-disable-next-line no-console
return console.trace;
case LogLevel.Debug:
// eslint-disable-next-line no-console
return console.debug;
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/logger/src/createLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class LoggerImpl implements Logger {
this.log(LogLevel.Error, ...args);
}
}

public trace(...args: string[]): void {
if (this.enabled) {
this.log(LogLevel.Trace, ...args);
}
}
}

export function createLogger(log: (level: LogLevel, ...args: string[]) => void): Logger {
Expand Down
3 changes: 3 additions & 0 deletions packages/seed/src/commands/test/TaskContextFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class TaskContextFactory {
case "info":
CONSOLE_LOGGER.info(`[${prefixWithColor}]: `, part);
break;
case "trace":
CONSOLE_LOGGER.trace(`[${prefixWithColor}]: `, part);
break;
default:
assertNever(log.level);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/snippets/core/src/utils/NopLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type LogLevel = "debug" | "info" | "warn" | "error";
export type LogLevel = "debug" | "info" | "warn" | "error" | "trace";

export class NopLogger {
public disable(): void {
Expand All @@ -9,6 +9,10 @@ export class NopLogger {
// no-op
}

public trace(...args: string[]): void {
// no-op
}

public debug(...args: string[]): void {
// no-op
}
Expand Down

0 comments on commit b623a66

Please sign in to comment.