Skip to content

Commit 3cb162a

Browse files
committed
Remove excessive debug logging across various services and components to streamline code and improve readability. Update logging levels from info to error where appropriate, and ensure consistent handling of locale data in migration processes.
1 parent 37d835a commit 3cb162a

File tree

15 files changed

+29
-211
lines changed

15 files changed

+29
-211
lines changed

api/src/services/drupal/query.service.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ export const createQuery = async (
344344
destination_stack_id
345345
);
346346

347-
console.info(
348-
`🔍 query.service.ts - Database connection established successfully`
349-
);
350-
351347
// SQL query to extract field configuration from Drupal
352348
const configQuery =
353349
"SELECT *, CONVERT(data USING utf8) as data FROM config WHERE name LIKE '%field.field.node%'";
@@ -376,7 +372,7 @@ export const createQuery = async (
376372
});
377373
}
378374
} catch (err: any) {
379-
console.warn(`Couldn't parse row ${i}:`, err.message);
375+
console.error(`Couldn't parse row ${i}:`, err.message);
380376
}
381377
}
382378

api/src/services/migration.service.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,19 +1073,6 @@ const startMigration = async (req: Request): Promise<any> => {
10731073
);
10741074
// 🔍 DEBUG: Log master_locale before passing to createEntry
10751075
const masterLocaleForContentful = project?.stackDetails?.master_locale;
1076-
console.info(
1077-
'🔍 Contentful startMigration - master_locale before createEntry:',
1078-
{
1079-
master_locale: masterLocaleForContentful,
1080-
master_locale_type: typeof masterLocaleForContentful,
1081-
master_locale_isLowercase:
1082-
masterLocaleForContentful ===
1083-
masterLocaleForContentful?.toLowerCase?.(),
1084-
master_locale_toLowerCase:
1085-
masterLocaleForContentful?.toLowerCase?.(),
1086-
project_stackDetails: project?.stackDetails,
1087-
}
1088-
);
10891076

10901077
await contentfulService?.createEntry(
10911078
cleanLocalPath,
@@ -1603,15 +1590,6 @@ export const createSourceLocales = async (req: Request) => {
16031590
if (index > -1) {
16041591
ProjectModelLowdb?.update?.((data: any) => {
16051592
data.projects[index].source_locales = locales;
1606-
1607-
console.info(
1608-
'✅ [createSourceLocales] Saved source_locales to project:',
1609-
{
1610-
projectId,
1611-
saved_source_locales: locales,
1612-
first_element_master: locales[0] || 'NONE',
1613-
}
1614-
);
16151593
});
16161594
} else {
16171595
logger.error(`Project with ID: ${projectId} not found`, {
@@ -1691,23 +1669,6 @@ export const updateLocaleMapper = async (req: Request) => {
16911669
.get('projects')
16921670
.find({ id: projectId })
16931671
.value();
1694-
console.info(
1695-
'================================================================================'
1696-
);
1697-
console.info(
1698-
'🔍 [API updateLocaleMapper] Saved locale data to database:'
1699-
);
1700-
console.info(' Project ID:', projectId);
1701-
console.info(' master_locale:', updatedProject?.master_locale);
1702-
console.info(' locales:', updatedProject?.locales);
1703-
console.info(' localeMapping:', updatedProject?.localeMapping);
1704-
console.info(
1705-
' localeMapping keys:',
1706-
Object.keys(updatedProject?.localeMapping || {})
1707-
);
1708-
console.info(
1709-
'================================================================================'
1710-
);
17111672

17121673
// 🔍 LOGGING: Log after update
17131674
await ProjectModelLowdb?.read?.();

api/src/utils/batch-processor.utils.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class BatchProcessor<T> {
1515
constructor(options: BatchProcessorOptions) {
1616
this.options = {
1717
delayBetweenBatches: 100, // Default 100ms delay
18-
...options
18+
...options,
1919
};
2020
}
2121

@@ -25,23 +25,27 @@ export class BatchProcessor<T> {
2525
async processBatches<R>(
2626
items: T[],
2727
processor: (item: T) => Promise<R>,
28-
onBatchComplete?: (batchIndex: number, totalBatches: number, results: R[]) => void
28+
onBatchComplete?: (
29+
batchIndex: number,
30+
totalBatches: number,
31+
results: R[]
32+
) => void
2933
): Promise<R[]> {
3034
const { batchSize, concurrency, delayBetweenBatches } = this.options;
3135
const totalBatches = Math.ceil(items.length / batchSize);
3236
const allResults: R[] = [];
3337

34-
console.log(`📦 Processing ${items.length} items in ${totalBatches} batches (${batchSize} items per batch, concurrency: ${concurrency})`);
35-
3638
for (let batchIndex = 0; batchIndex < totalBatches; batchIndex++) {
3739
const startIndex = batchIndex * batchSize;
3840
const endIndex = Math.min(startIndex + batchSize, items.length);
3941
const batch = items.slice(startIndex, endIndex);
4042

41-
console.log(`📋 Processing batch ${batchIndex + 1}/${totalBatches} (${batch.length} items)`);
42-
4343
// Process batch with controlled concurrency
44-
const batchResults = await this.processBatchWithConcurrency(batch, processor, concurrency);
44+
const batchResults = await this.processBatchWithConcurrency(
45+
batch,
46+
processor,
47+
concurrency
48+
);
4549
allResults.push(...batchResults);
4650

4751
// Callback for batch completion
@@ -50,7 +54,11 @@ export class BatchProcessor<T> {
5054
}
5155

5256
// Delay between batches to allow file handles to close
53-
if (batchIndex < totalBatches - 1 && delayBetweenBatches && delayBetweenBatches > 0) {
57+
if (
58+
batchIndex < totalBatches - 1 &&
59+
delayBetweenBatches &&
60+
delayBetweenBatches > 0
61+
) {
5462
await this.delay(delayBetweenBatches);
5563
}
5664

@@ -60,7 +68,6 @@ export class BatchProcessor<T> {
6068
}
6169
}
6270

63-
console.log(`✅ Completed processing ${items.length} items in ${totalBatches} batches`);
6471
return allResults;
6572
}
6673

@@ -73,7 +80,7 @@ export class BatchProcessor<T> {
7380
concurrency: number
7481
): Promise<R[]> {
7582
const results: R[] = [];
76-
83+
7784
for (let i = 0; i < batch.length; i += concurrency) {
7885
const chunk = batch.slice(i, i + concurrency);
7986
const chunkPromises = chunk.map(processor);
@@ -88,7 +95,7 @@ export class BatchProcessor<T> {
8895
* Delay utility
8996
*/
9097
private delay(ms: number): Promise<void> {
91-
return new Promise(resolve => setTimeout(resolve, ms));
98+
return new Promise((resolve) => setTimeout(resolve, ms));
9299
}
93100
}
94101

@@ -99,7 +106,11 @@ export async function processBatches<T, R>(
99106
items: T[],
100107
processor: (item: T) => Promise<R>,
101108
options: BatchProcessorOptions,
102-
onBatchComplete?: (batchIndex: number, totalBatches: number, results: R[]) => void
109+
onBatchComplete?: (
110+
batchIndex: number,
111+
totalBatches: number,
112+
results: R[]
113+
) => void
103114
): Promise<R[]> {
104115
const batchProcessor = new BatchProcessor<T>(options);
105116
return batchProcessor.processBatches(items, processor, onBatchComplete);

api/src/utils/content-type-creator.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ export const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath
960960
"non_localizable": field.advanced?.nonLocalizable ?? false,
961961
}
962962
} else {
963-
console.info('Content Type Field', field?.contentstackField)
963+
console.error('Content Type Field', field?.contentstackField)
964964
}
965965
}
966966
}
@@ -1174,6 +1174,6 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
11741174
await saveContent(ct, contentSave);
11751175
}
11761176
} else {
1177-
console.info(contentType?.contentstackUid, 'missing');
1177+
console.error(contentType?.contentstackUid, 'missing');
11781178
}
11791179
};

api/src/utils/custom-logger.utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,13 @@ const customLogger = async (
6868

6969
if (!fs.existsSync(logFilePath)) {
7070
// If the file does not exist, create it and write an initial log entry
71-
console.info(`Creating new log file at: ${logFilePath}`);
7271
// Conditionally log stack trace based on environment
7372
if (process.env.NODE_ENV !== 'production') {
7473
console.info(new Error().stack);
7574
}
7675
await fs.promises.writeFile(logFilePath, 'Log file created\n', {
7776
flag: 'a',
7877
});
79-
console.info(
80-
`Log file created and initial entry written: ${logFilePath}`
81-
);
8278
}
8379
// Create a logger instance with a file transport
8480
const log = createLogger({

api/src/utils/sanitize-path.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path';
77
* @param filename - The input filename to sanitize.
88
* @returns A safe, sanitized filename.
99
*/
10-
export const sanitizeFilename = (filename: string): string => {
10+
const sanitizeFilename = (filename: string): string => {
1111
return path.basename(filename).replace(/[^a-zA-Z0-9_.\s-]/g, '');
1212
};
1313

ui/src/components/Common/AddStack/addStack.tsx

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,6 @@ const AddStack = (props: any): JSX.Element => {
114114
const rawMasterLocale = sourceLocales.length > 0 ? sourceLocales[0] : 'en-us';
115115
const masterLocale = (typeof rawMasterLocale === 'string' ? rawMasterLocale : rawMasterLocale?.label || rawMasterLocale?.value || 'en-us').toLowerCase();
116116

117-
// 🔍 DEBUG: Log master locale detection (FIRST element from source_locales)
118-
console.info('================================================================================');
119-
console.info('🔍 AddStack - Master locale detection (source_locales[0]):', {
120-
sourceLocales,
121-
sourceLocales_length: sourceLocales.length,
122-
sourceLocales_first_element: sourceLocales[0],
123-
rawMasterLocale,
124-
masterLocale_after_lowercase: masterLocale,
125-
masterLocale_type: typeof masterLocale,
126-
isLowercase: masterLocale === masterLocale?.toLowerCase?.(),
127-
});
128-
console.info('🔍 AddStack - Contentstack locales sample (first 3):',
129-
rawMappedLocalesMapped?.slice(0, 3)?.map(l => ({
130-
value: l.value,
131-
value_lowercase: l.value?.toLowerCase(),
132-
label: l.label
133-
}))
134-
);
135-
console.info('================================================================================');
136-
137117
// 🔧 CRITICAL: Find matching Contentstack locale (all lowercase comparison)
138118
const matchingLocale = rawMappedLocalesMapped.find(locale => {
139119
const localeValueLower = (locale.value || '').toLowerCase();
@@ -149,15 +129,6 @@ const AddStack = (props: any): JSX.Element => {
149129
return false;
150130
});
151131

152-
// 🔍 DEBUG: Log matching result
153-
console.info('🔍 AddStack - Matching Contentstack locale:', {
154-
matchingLocale,
155-
matchingLocale_value: matchingLocale?.value,
156-
matchingLocale_value_lowercase: matchingLocale?.value?.toLowerCase(),
157-
will_auto_select: !!matchingLocale
158-
});
159-
console.info('================================================================================');
160-
161132
setAllLocales(rawMappedLocalesMapped);
162133

163134
// Update form with correct master locale after locales are loaded
@@ -184,15 +155,6 @@ const AddStack = (props: any): JSX.Element => {
184155
const rawMasterLocale = sourceLocales.length > 0 ? sourceLocales[0] : 'en-us';
185156
const masterLocale = (typeof rawMasterLocale === 'string' ? rawMasterLocale : rawMasterLocale?.label || rawMasterLocale?.value || 'en-us').toLowerCase();
186157

187-
// 🔍 DEBUG: Log master locale in useEffect (source_locales[0])
188-
console.info('🔍 AddStack useEffect - Re-checking master locale:', {
189-
sourceLocales,
190-
sourceLocales_first_element: sourceLocales[0],
191-
rawMasterLocale,
192-
masterLocale_after_lowercase: masterLocale,
193-
allLocales_count: allLocales.length
194-
});
195-
196158
// 🔧 CRITICAL: Find matching Contentstack locale (all lowercase comparison)
197159
const matchingLocale = allLocales.find(locale => {
198160
const localeValueLower = (locale.value || '').toLowerCase();
@@ -208,15 +170,7 @@ const AddStack = (props: any): JSX.Element => {
208170
return false;
209171
});
210172

211-
// 🔍 DEBUG: Log matching result in useEffect
212-
console.info('🔍 AddStack useEffect - Final matching locale:', {
213-
matchingLocale,
214-
matchingLocale_value: matchingLocale?.value,
215-
will_update_form: !!matchingLocale
216-
});
217-
218173
if (matchingLocale) {
219-
console.info('✅ AddStack - Auto-selecting master locale:', matchingLocale.value);
220174
formRef.current.change('locale', matchingLocale);
221175
} else {
222176
console.warn('⚠️ AddStack - No matching Contentstack locale found for:', masterLocale);

ui/src/components/ContentMapper/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
691691
// delete updatedOptions[key];
692692
// }
693693
// });
694-
// console.info("updatedOptions", updatedOptions);
695694
// return updatedOptions;
696695
// });
697696

ui/src/components/DestinationStack/Actions/LoadStacks.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ const LoadStacks = (props: LoadFileFormatProps) => {
114114
// 🔧 CRITICAL: Ensure master_locale is always lowercase
115115
const masterLocale = (data?.locale || '').toLowerCase();
116116

117-
console.info('🔍 LoadStacks - Creating new stack:', {
118-
stack_name: data?.name,
119-
raw_locale: data?.locale,
120-
master_locale_lowercase: masterLocale,
121-
description: data?.description
122-
});
123-
124117
// Post data to backend
125118
const resp = await createStacksInOrg(selectedOrganisation?.value, {
126119
...data,

ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
126126

127127
const { data, status } = await fileValidation(projectId, newMigrationData?.legacy_cms?.affix);
128128

129-
/* eslint-disable no-console */
130-
console.log('📥 UI - API Response received:');
131-
console.log(' status:', status);
132-
console.log(' data.file_details.isSQL:', data?.file_details?.isSQL);
133-
console.log(' data.file_details.cmsType:', data?.file_details?.cmsType);
134-
console.log(' Full data:', data);
135-
/* eslint-enable no-console */
136-
137129
setProgressPercentage(70);
138130
setProcessing('Processing...70%');
139131

@@ -312,7 +304,6 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
312304
//setIsFormatValid(isFormatValid);
313305
setIsDisabled(!isFormatValid || isEmptyString(newMigrationDataRef?.current?.legacy_cms?.affix));
314306
if(!isFormatValid){
315-
console.warn('⚠️ LoadUploadFile: File format is not valid, setting isValidated to false');
316307
setValidationMessage('');
317308
// ✅ FIX: Properly spread existing data to prevent data loss
318309
dispatch(updateNewMigrationData({
@@ -526,21 +517,13 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
526517
disabled={!(reValidate || (!isDisabled))}
527518
>
528519
{(() => {
529-
/* eslint-disable no-console */
530-
console.log('=== BUTTON LABEL DEBUG ===');
531-
console.log('fileDetails:', fileDetails);
532-
console.log('fileDetails.isLocalPath:', fileDetails?.isLocalPath);
533-
console.log('fileDetails.isSQL:', fileDetails?.isSQL);
534-
535520
// Logic: If using local path, always "File Validate"
536521
// If not using local path AND using SQL, then "Check Connection"
537522
// Otherwise "File Validate"
538523
const buttonText = fileDetails?.isLocalPath
539524
? 'File Validate'
540525
: (fileDetails?.isSQL ? 'Check Connection' : 'File Validate');
541526

542-
console.log('Button text will be:', buttonText);
543-
/* eslint-enable no-console */
544527
return buttonText;
545528
})()}
546529
</Button>

0 commit comments

Comments
 (0)