From 880109c9608bb7eb00fee3da15199c7f70a41020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Wed, 22 Nov 2023 13:40:05 +0100 Subject: [PATCH 1/3] Override Notion Client logger --- .../src/connectors/notion/lib/notion_api.ts | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/connectors/src/connectors/notion/lib/notion_api.ts b/connectors/src/connectors/notion/lib/notion_api.ts index 94850a71f3a3..6efdec08ea60 100644 --- a/connectors/src/connectors/notion/lib/notion_api.ts +++ b/connectors/src/connectors/notion/lib/notion_api.ts @@ -4,6 +4,7 @@ import { isFullBlock, isFullDatabase, isFullPage, + LogLevel, } from "@notionhq/client"; import { BlockObjectResponse, @@ -30,6 +31,14 @@ import mainLogger from "@connectors/logger/logger"; const logger = mainLogger.child({ provider: "notion" }); +const notionClientLogger = ( + level: LogLevel, + message: string, + extraInfo: Record +) => { + console.log(`[${level}]: ${message}`, extraInfo); +}; + /** * @param notionAccessToken the access token to use to access the Notion API * @param sinceTs a millisecond timestamp representing the minimum last edited time of @@ -58,7 +67,10 @@ export async function getPagesAndDatabasesEditedSince( }> { const localLogger = logger.child(loggerArgs); - const notionClient = new Client({ auth: notionAccessToken }); + const notionClient = new Client({ + auth: notionAccessToken, + logger: notionClientLogger, + }); const editedPages: Record = {}; const editedDbs: Record = {}; let resultsPage: SearchResponse | null = null; @@ -217,7 +229,10 @@ export async function getDatabaseChildPages({ }> { const localLogger = logger.child(loggerArgs); - const notionClient = new Client({ auth: notionAccessToken }); + const notionClient = new Client({ + auth: notionAccessToken, + logger: notionClientLogger, + }); let resultsPage: QueryDatabaseResponse | null = null; const pages: Record = {}; @@ -294,7 +309,10 @@ export async function isAccessibleAndUnarchived( objectType: "page" | "database", localLogger?: Logger ): Promise { - const notionClient = new Client({ auth: notionAccessToken }); + const notionClient = new Client({ + auth: notionAccessToken, + logger: notionClientLogger, + }); const maxTries = 5; let tries = 0; @@ -373,7 +391,10 @@ async function getBlockParent( const max_depth = 8; const max_transient_errors = 5; - const notionClient = new Client({ auth: notionAccessToken }); + const notionClient = new Client({ + auth: notionAccessToken, + logger: notionClientLogger, + }); let depth = 0; let transient_errors = 0; @@ -442,7 +463,10 @@ export async function getParsedDatabase( ): Promise { const localLogger = logger.child({ ...loggerArgs, databaseId }); - const notionClient = new Client({ auth: notionAccessToken }); + const notionClient = new Client({ + auth: notionAccessToken, + logger: notionClientLogger, + }); let database: GetDatabaseResponse | null = null; @@ -533,7 +557,10 @@ export async function retrievePage({ }): Promise { const localLogger = logger.child({ ...loggerArgs, pageId }); - const notionClient = new Client({ auth: accessToken }); + const notionClient = new Client({ + auth: accessToken, + logger: notionClientLogger, + }); let page: GetPageResponse | null = null; try { @@ -582,7 +609,10 @@ export async function retrieveBlockChildrenResultPage({ }): Promise { const localLogger = logger.child(loggerArgs); - const notionClient = new Client({ auth: accessToken }); + const notionClient = new Client({ + auth: accessToken, + logger: notionClientLogger, + }); try { localLogger.info( @@ -668,7 +698,10 @@ export function getPageOrBlockParent( } export async function validateAccessToken(notionAccessToken: string) { - const notionClient = new Client({ auth: notionAccessToken }); + const notionClient = new Client({ + auth: notionAccessToken, + logger: notionClientLogger, + }); try { await notionClient.search({ page_size: 1 }); } catch (e) { @@ -768,7 +801,10 @@ export async function retrieveDatabaseChildrenResultPage({ }) { const localLogger = logger.child({ ...loggerArgs, databaseId }); - const notionClient = new Client({ auth: accessToken }); + const notionClient = new Client({ + auth: accessToken, + logger: notionClientLogger, + }); localLogger.info("Fetching database children result page from Notion API."); try { @@ -848,7 +884,10 @@ export async function getUserName( return nameFromCache; } - const notionClient = new Client({ auth: accessToken }); + const notionClient = new Client({ + auth: accessToken, + logger: notionClientLogger, + }); try { pageLogger.info({ user_id: userId }, "Fetching user name from Notion API."); From ccbc6a8a5e7653acd9cc4a4ba8424f354905cd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Wed, 22 Nov 2023 14:38:43 +0100 Subject: [PATCH 2/3] Do not even log --- connectors/src/connectors/notion/lib/notion_api.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/connectors/src/connectors/notion/lib/notion_api.ts b/connectors/src/connectors/notion/lib/notion_api.ts index 6efdec08ea60..f06c42f4d9ee 100644 --- a/connectors/src/connectors/notion/lib/notion_api.ts +++ b/connectors/src/connectors/notion/lib/notion_api.ts @@ -31,12 +31,8 @@ import mainLogger from "@connectors/logger/logger"; const logger = mainLogger.child({ provider: "notion" }); -const notionClientLogger = ( - level: LogLevel, - message: string, - extraInfo: Record -) => { - console.log(`[${level}]: ${message}`, extraInfo); +const notionClientLogger = () => { + // no-op }; /** From 40669e8d0c61a7136568f5f309dd7b9de83271d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Wed, 22 Nov 2023 14:44:50 +0100 Subject: [PATCH 3/3] Change my mind again --- connectors/src/connectors/notion/lib/notion_api.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/connectors/src/connectors/notion/lib/notion_api.ts b/connectors/src/connectors/notion/lib/notion_api.ts index f06c42f4d9ee..9d1aba6c7656 100644 --- a/connectors/src/connectors/notion/lib/notion_api.ts +++ b/connectors/src/connectors/notion/lib/notion_api.ts @@ -31,8 +31,12 @@ import mainLogger from "@connectors/logger/logger"; const logger = mainLogger.child({ provider: "notion" }); -const notionClientLogger = () => { - // no-op +const notionClientLogger = ( + level: LogLevel, + message: string, + extraInfo: Record +) => { + logger.info(`[Log from Notion Client] Level ${level}: ${message}`, extraInfo); }; /**