Skip to content

Commit 12dca06

Browse files
authored
reduce info logging (#131)
### Notes Reduced info log noise in client library.
1 parent d50004b commit 12dca06

File tree

5 files changed

+10
-70
lines changed

5 files changed

+10
-70
lines changed

src/hooks/custom/LoggerHook.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class LoggerHook implements AfterSuccessHook, AfterErrorHook {
4646
afterSuccess(hookCtx: AfterSuccessContext, response: Response): Response {
4747
this.retriesCounter.delete(hookCtx.operationID);
4848
// NOTE: In case of split page partition this means - at least one of the splits was partitioned successfully
49-
console.info("Successfully partitioned the document.");
5049
return response;
5150
}
5251

@@ -67,15 +66,14 @@ export class LoggerHook implements AfterSuccessHook, AfterErrorHook {
6766
this.logRetries(response, error, hookCtx.operationID);
6867

6968
if (response && response.status === 200) {
70-
console.info("Successfully partitioned the document.");
71-
} else {
72-
console.error("Failed to partition the document.");
73-
if (response) {
74-
console.error(`Server responded with ${response.status} - ${response.statusText}`);
75-
}
76-
if (error) {
77-
console.error(`Following error occurred - ${(error as Error).message}`);
78-
}
69+
return { response, error };
70+
}
71+
console.error("Failed to partition the document.");
72+
if (response) {
73+
console.error(`Server responded with ${response.status} - ${response.statusText}`);
74+
}
75+
if (error) {
76+
console.error(`Following error occurred - ${(error as Error).message}`);
7977
}
8078
return { response, error };
8179
}

src/hooks/custom/SplitPdfHook.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -110,36 +110,29 @@ export class SplitPdfHook
110110
const file = formData.get(PARTITION_FORM_FILES_KEY) as File | null;
111111

112112
if (!splitPdfPage) {
113-
console.info("Partitioning without split.")
114113
return request;
115114
}
116115

117-
console.info("Preparing to split document for partition.")
118116
if (!this.client) {
119117
console.warn("HTTP client not accessible! Partitioning without split.");
120118
return request;
121119
}
122120

123121
const [error, pdf, totalPages] = await loadPdf(file);
124122
if (file === null || pdf === null || error) {
125-
console.info("Partitioning without split.")
126123
return request;
127124
}
128125

129126
const [pageRangeStart, pageRangeEnd] = getSplitPdfPageRange(formData, totalPages);
130127
const pagesCount = pageRangeEnd - pageRangeStart + 1;
131128

132129
const startingPageNumber = getStartingPageNumber(formData);
133-
console.info("Starting page number set to %d", startingPageNumber);
134130

135131
const concurrencyLevel = getSplitPdfConcurrencyLevel(formData);
136-
console.info("Concurrency level set to %d", concurrencyLevel)
137132

138133
this.allowFailed = getSplitPdfAllowFailed(formData);
139-
console.info("Allow failed set to %s", this.allowFailed)
140134

141135
const splitSize = await getOptimalSplitSize(pagesCount, concurrencyLevel);
142-
console.info("Determined optimal split size of %d pages.", splitSize)
143136

144137
// If user wants a specific page range, we need to call splitPdf,
145138
// even if this page count is too small to be split normally
@@ -148,26 +141,11 @@ export class SplitPdfHook
148141
// Otherwise, if there are not enough pages, return the original request without splitting
149142
if (!isPageRangeRequested) {
150143
if (splitSize >= pagesCount || pagesCount < MIN_PAGES_PER_THREAD) {
151-
console.info(
152-
"Document has too few pages (%d) to be split efficiently. Partitioning without split.",
153-
pagesCount,
154-
)
155144
return request;
156145
}
157146
}
158147

159148
const splits = await splitPdf(pdf, splitSize, pageRangeStart, pageRangeEnd);
160-
const numberOfSplits = splits.length
161-
console.info(
162-
"Document split into %d, %d-paged sets.",
163-
numberOfSplits,
164-
splitSize,
165-
)
166-
console.info(
167-
"Partitioning %d, %d-paged sets.",
168-
numberOfSplits,
169-
splitSize,
170-
)
171149

172150
const oneSecond = 1000;
173151
const oneMinute = 1000 * 60;
@@ -181,12 +159,6 @@ export class SplitPdfHook
181159
for (const { content, startPage } of splits) {
182160
// Both startPage and startingPageNumber are 1-based, so we need to subtract 1
183161
const firstPageNumber = startPage + startingPageNumber - 1;
184-
console.info(
185-
"Partitioning set #%d (pages %d-%d).",
186-
setIndex,
187-
firstPageNumber,
188-
Math.min(firstPageNumber + splitSize - 1, pagesCount),
189-
);
190162

191163
const body = await prepareRequestBody(
192164
formData,
@@ -261,8 +233,7 @@ export class SplitPdfHook
261233
concurrencyLevel
262234
);
263235

264-
const dummyRequest = new Request("https://no-op/");
265-
return dummyRequest;
236+
return new Request("https://no-op/");
266237
}
267238

268239
/**

src/hooks/custom/utils/form.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ export function getSplitPdfConcurrencyLevel(formData: FormData): number {
135135
);
136136
splitPdfConcurrencyLevel = DEFAULT_NUMBER_OF_PARALLEL_REQUESTS;
137137
}
138-
139-
console.info(
140-
`Splitting PDF by page on client. Using ${splitPdfConcurrencyLevel} threads when calling API.`
141-
);
142-
console.info(
143-
`Set ${PARTITION_FORM_SPLIT_PDF_CONCURRENCY_LEVEL} parameter if you want to change that.`
144-
);
145138
return splitPdfConcurrencyLevel;
146139
}
147140

@@ -165,25 +158,6 @@ export function getSplitPdfAllowFailed(formData: FormData): boolean {
165158
PARTITION_FORM_SPLIT_PDF_ALLOW_FAILED_KEY,
166159
DEFAULT_SPLIT_PDF_ALLOW_FAILED_KEY
167160
);
168-
169-
170-
if (splitPdfAllowFailed) {
171-
console.info(
172-
`Running split PDF requests in parallel with no-strict mode -
173-
the failed requests will not stop the process, and the resulting elements might miss
174-
some pages in case of failure.`
175-
);
176-
} else {
177-
console.info(
178-
`Running split PDF requests in parallel with strict mode -
179-
the failed requests will stop the process, and the resulting elements will have all pages
180-
or error out.`
181-
)
182-
}
183-
184-
console.info(
185-
`Set ${PARTITION_FORM_SPLIT_PDF_CONCURRENCY_LEVEL} parameter if you want to change that.`
186-
);
187161
return splitPdfAllowFailed;
188162
}
189163

src/hooks/custom/utils/pdf.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export async function loadPdf(
109109
file: File | null
110110
): Promise<[boolean, PDFDocument | null, number]> {
111111
if (!file) {
112-
console.info("Given file is null, so splitting is not enabled.");
113112
return [true, null, 0];
114113
}
115114

src/hooks/custom/utils/request.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export async function prepareResponseBody(
3131
const allElements: any[] = [];
3232
let index = 1;
3333
for (const res of responses) {
34-
if (res.status == 200) {
35-
console.info("Successfully partitioned set #%d, elements added to the final result.", index);
36-
} else {
34+
if (res.status != 200) {
3735
console.warn("Failed to partition set #%d, its elements will be omitted in the final result.", index);
3836
}
3937

0 commit comments

Comments
 (0)