mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 01:31:05 +00:00
Added option to enable AWS CRT debug logging
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user