From 6c24d59760268ebac372822b199da4d6eeb56889 Mon Sep 17 00:00:00 2001 From: Pascal Bourque Date: Sun, 23 Nov 2025 10:29:41 -0500 Subject: [PATCH] Added option to enable AWS CRT debug logging --- example/main.ts | 7 ++++++- src/api/MysaApiClient.ts | 6 +++++- src/api/MysaApiClientOptions.ts | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/example/main.ts b/example/main.ts index 4eb5d60..d271bc7 100644 --- a/example/main.ts +++ b/example/main.ts @@ -20,6 +20,7 @@ const rootLogger = pino({ /** Main entry point of the example application. */ async function main() { let session: MysaSession | undefined; + try { rootLogger.info('Loading session...'); const sessionJson = await readFile('session.json', 'utf8'); @@ -27,7 +28,11 @@ async function main() { } catch { rootLogger.info('No valid session file found.'); } - const client = new MysaApiClient(session, { logger: rootLogger.child({ module: 'mysa-js-sdk' }) }); + + const client = new MysaApiClient(session, { + logger: rootLogger.child({ module: 'mysa-js-sdk' }), + isAwsCrtDebugLoggingEnabled: process.env.AWS_CRT_DEBUG_LOGGING === '1' + }); client.emitter.on('sessionChanged', async (newSession) => { if (newSession) { diff --git a/src/api/MysaApiClient.ts b/src/api/MysaApiClient.ts index 127fda7..1ef9825 100644 --- a/src/api/MysaApiClient.ts +++ b/src/api/MysaApiClient.ts @@ -18,7 +18,7 @@ import { CognitoUserPool, CognitoUserSession } from 'amazon-cognito-identity-js'; -import { iot, mqtt } from 'aws-iot-device-sdk-v2'; +import { io, iot, mqtt } from 'aws-iot-device-sdk-v2'; import { hash } from 'crypto'; import dayjs, { Dayjs } from 'dayjs'; import duration from 'dayjs/plugin/duration.js'; @@ -152,6 +152,10 @@ export class MysaApiClient { this._logger = options?.logger || new VoidLogger(); this._fetcher = options?.fetcher || fetch; + if (options?.isAwsCrtDebugLoggingEnabled) { + io.enable_logging(io.LogLevel.DEBUG); + } + if (session) { this._cognitoUser = new CognitoUser({ Username: session.username, diff --git a/src/api/MysaApiClientOptions.ts b/src/api/MysaApiClientOptions.ts index 08d40a3..664e059 100644 --- a/src/api/MysaApiClientOptions.ts +++ b/src/api/MysaApiClientOptions.ts @@ -15,4 +15,11 @@ export interface MysaApiClientOptions { * @defaultValue The global `fetch` function. */ fetcher?: typeof fetch; + + /** + * Whether to enable debug logging for AWS CRT. + * + * @defaultValue `false` + */ + isAwsCrtDebugLoggingEnabled?: boolean; }