Added option to enable AWS CRT debug logging

This commit is contained in:
Pascal Bourque
2025-11-23 10:29:41 -05:00
parent f7c3dc07b3
commit 6c24d59760
3 changed files with 18 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ const rootLogger = pino({
/** Main entry point of the example application. */ /** Main entry point of the example application. */
async function main() { async function main() {
let session: MysaSession | undefined; let session: MysaSession | undefined;
try { try {
rootLogger.info('Loading session...'); rootLogger.info('Loading session...');
const sessionJson = await readFile('session.json', 'utf8'); const sessionJson = await readFile('session.json', 'utf8');
@@ -27,7 +28,11 @@ async function main() {
} catch { } catch {
rootLogger.info('No valid session file found.'); 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) => { client.emitter.on('sessionChanged', async (newSession) => {
if (newSession) { if (newSession) {

View File

@@ -18,7 +18,7 @@ import {
CognitoUserPool, CognitoUserPool,
CognitoUserSession CognitoUserSession
} from 'amazon-cognito-identity-js'; } 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 { hash } from 'crypto';
import dayjs, { Dayjs } from 'dayjs'; import dayjs, { Dayjs } from 'dayjs';
import duration from 'dayjs/plugin/duration.js'; import duration from 'dayjs/plugin/duration.js';
@@ -152,6 +152,10 @@ export class MysaApiClient {
this._logger = options?.logger || new VoidLogger(); this._logger = options?.logger || new VoidLogger();
this._fetcher = options?.fetcher || fetch; this._fetcher = options?.fetcher || fetch;
if (options?.isAwsCrtDebugLoggingEnabled) {
io.enable_logging(io.LogLevel.DEBUG);
}
if (session) { if (session) {
this._cognitoUser = new CognitoUser({ this._cognitoUser = new CognitoUser({
Username: session.username, Username: session.username,

View File

@@ -15,4 +15,11 @@ export interface MysaApiClientOptions {
* @defaultValue The global `fetch` function. * @defaultValue The global `fetch` function.
*/ */
fetcher?: typeof fetch; fetcher?: typeof fetch;
/**
* Whether to enable debug logging for AWS CRT.
*
* @defaultValue `false`
*/
isAwsCrtDebugLoggingEnabled?: boolean;
} }