Skip to content

Commit

Permalink
feat(logs): Add more detail to sync logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dvanoni committed Aug 25, 2024
1 parent b339fcc commit 9a86eae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/content/sync/notion-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Client, Logger } from '@notionhq/client';
import { Client, Logger, LogLevel } from '@notionhq/client';

import { getRequiredNoteroPref, NoteroPref } from '../prefs/notero-pref';
import { logger } from '../utils';

const notionLogger: Logger = (level, message, extraInfo) => {
level = level === LogLevel.INFO ? LogLevel.DEBUG : level;
logger[level](message, extraInfo);
};

Expand All @@ -14,5 +15,6 @@ export function getNotionClient(window: Window) {
auth: authToken,
fetch: window.fetch.bind(window),
logger: notionLogger,
logLevel: LogLevel.DEBUG,
});
}
10 changes: 7 additions & 3 deletions src/content/sync/sync-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ class SyncJob {
public async perform() {
for (const [index, item] of this.items.entries()) {
const step = index + 1;
logger.debug(
`Syncing item ${step} of ${this.items.length} with ID ${item.id}\n `,
item.getDisplayTitle(),
logger.groupCollapsed(
`Syncing item ${step} of ${this.items.length} with ID ${item.id}`,
);
logger.debug(item.getDisplayTitle());

this.progressWindow.updateText(step);

Expand All @@ -166,6 +166,8 @@ class SyncJob {
}
} catch (error) {
throw new ItemSyncError(error, item);
} finally {
logger.groupEnd();
}

this.progressWindow.updateProgress(step);
Expand Down Expand Up @@ -204,6 +206,7 @@ class SyncJob {

if (pageID) {
try {
logger.debug('Update page', pageID, properties);
return await this.notion.pages.update({ page_id: pageID, properties });
} catch (error) {
if (!isNotionErrorWithCode(error, APIErrorCode.ObjectNotFound)) {
Expand All @@ -212,6 +215,7 @@ class SyncJob {
}
}

logger.debug('Create page', properties);
return await this.notion.pages.create({
parent: { database_id: this.databaseID },
properties,
Expand Down

0 comments on commit 9a86eae

Please sign in to comment.