Skip to content

Commit fb8ca8c

Browse files
committed
fix: get rid of noisy logs
1 parent 55431fe commit fb8ca8c

File tree

2 files changed

+28
-64
lines changed

2 files changed

+28
-64
lines changed

packages/new-compiler/src/translators/pluralization/service.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class PluralizationService {
5656
this.sourceLocale = config.sourceLocale;
5757
this.prompt = getSystemPrompt({ sourceLocale: config.sourceLocale });
5858

59-
this.logger.info(
59+
this.logger.debug(
6060
`Initialized pluralization service with ${localeModel.provider}:${localeModel.name}`,
6161
);
6262
}
@@ -72,22 +72,23 @@ export class PluralizationService {
7272
candidates: PluralCandidate[],
7373
batchSize: number = 10,
7474
): Promise<Map<string, ICUGenerationResult>> {
75-
const results = new Map<string, ICUGenerationResult>();
76-
77-
// Check cache first
78-
const uncachedCandidates = candidates.filter((c) => {
79-
const cached = this.cache.get(c.hash);
80-
if (cached) {
81-
results.set(c.hash, cached);
82-
return false;
83-
}
84-
return true;
85-
});
75+
const { uncachedCandidates, results } = candidates.reduce(
76+
(acc, c) => {
77+
const cached = this.cache.get(c.hash);
78+
if (cached) {
79+
acc.results.set(c.hash, cached);
80+
} else {
81+
acc.uncachedCandidates.push(c);
82+
}
83+
return acc;
84+
},
85+
{
86+
uncachedCandidates: [] as PluralCandidate[],
87+
results: new Map<string, ICUGenerationResult>(),
88+
},
89+
);
8690

8791
if (uncachedCandidates.length === 0) {
88-
this.logger.debug(
89-
`All ${candidates.length} candidates found in cache, skipping LLM call`,
90-
);
9192
return results;
9293
}
9394

packages/new-compiler/src/translators/translation-service.ts

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -154,36 +154,24 @@ export class TranslationService {
154154
// Step 1: Determine which hashes we need to work with
155155
const workingHashes = requestedHashes || Object.keys(metadata.entries);
156156

157-
this.logger.info(
157+
this.logger.debug(
158158
`Translation requested for ${workingHashes.length} hashes in locale: ${locale}`,
159159
);
160160

161161
// Step 2: Check cache first (same for all locales, including source)
162-
this.logger.debug(`[TRACE] Checking cache for locale: ${locale}`);
163-
const cacheStartTime = performance.now();
164162
const cachedTranslations = await this.cache.get(locale);
165-
const cacheEndTime = performance.now();
166-
this.logger.debug(
167-
`[TRACE] Cache check completed in ${(cacheEndTime - cacheStartTime).toFixed(2)}ms, found ${Object.keys(cachedTranslations).length} entries`,
168-
);
169163

170164
// Step 3: Determine what needs translation/pluralization
171165
const uncachedHashes = workingHashes.filter(
172166
(hash) => !cachedTranslations[hash],
173167
);
174168
this.logger.debug(
175-
`[TRACE] ${uncachedHashes.length} hashes need processing, ${workingHashes.length - uncachedHashes.length} are cached`,
169+
`${uncachedHashes.length} hashes need processing, ${workingHashes.length - uncachedHashes.length} are cached`,
176170
);
177171

178172
const cachedCount = workingHashes.length - uncachedHashes.length;
179173

180174
if (uncachedHashes.length === 0) {
181-
// All cached!
182-
const endTime = performance.now();
183-
this.logger.info(
184-
`Cache hit for all ${workingHashes.length} hashes in ${locale} in ${(endTime - startTime).toFixed(2)}ms`,
185-
);
186-
187175
return {
188176
translations: this.pickTranslations(cachedTranslations, workingHashes),
189177
errors: [],
@@ -196,7 +184,7 @@ export class TranslationService {
196184
};
197185
}
198186

199-
this.logger.info(
187+
this.logger.debug(
200188
`Generating translations for ${uncachedHashes.length} uncached hashes in ${locale}...`,
201189
);
202190

@@ -212,12 +200,12 @@ export class TranslationService {
212200

213201
// Step 5: Process pluralization for filtered entries
214202
if (this.pluralizationService) {
215-
this.logger.info(
203+
this.logger.debug(
216204
`Processing pluralization for ${Object.keys(filteredMetadata.entries).length} entries...`,
217205
);
218206
const pluralStats =
219207
await this.pluralizationService.process(filteredMetadata);
220-
this.logger.info(
208+
this.logger.debug(
221209
`Pluralization stats: ${pluralStats.pluralized} pluralized, ${pluralStats.rejected} rejected, ${pluralStats.failed} failed`,
222210
);
223211
}
@@ -227,7 +215,7 @@ export class TranslationService {
227215
const hashesNeedingTranslation: string[] = [];
228216

229217
this.logger.debug(
230-
`[TRACE] Checking for overrides in ${uncachedHashes.length} entries`,
218+
`Checking for overrides in ${uncachedHashes.length} entries`,
231219
);
232220

233221
for (const hash of uncachedHashes) {
@@ -238,31 +226,20 @@ export class TranslationService {
238226
if (entry.overrides && entry.overrides[locale]) {
239227
overriddenTranslations[hash] = entry.overrides[locale];
240228
this.logger.debug(
241-
`[TRACE] Using override for ${hash} in locale ${locale}: "${entry.overrides[locale]}"`,
229+
`Using override for ${hash} in locale ${locale}: "${entry.overrides[locale]}"`,
242230
);
243231
} else {
244232
hashesNeedingTranslation.push(hash);
245233
}
246234
}
247235

248236
const overrideCount = Object.keys(overriddenTranslations).length;
249-
if (overrideCount > 0) {
250-
this.logger.info(
251-
`Found ${overrideCount} override(s) for locale ${locale}, skipping AI translation for these entries`,
252-
);
253-
}
254237

255238
// Step 7: Prepare entries for translation (excluding overridden ones)
256-
this.logger.debug(
257-
`[TRACE] Preparing ${hashesNeedingTranslation.length} entries for translation (after overrides)`,
258-
);
259239
const entriesToTranslate = this.prepareEntries(
260240
filteredMetadata,
261241
hashesNeedingTranslation,
262242
);
263-
this.logger.debug(
264-
`[TRACE] Prepared ${Object.keys(entriesToTranslate).length} entries`,
265-
);
266243

267244
// Step 8: Translate or return source text
268245
let newTranslations: Record<string, string> = { ...overriddenTranslations };
@@ -271,7 +248,7 @@ export class TranslationService {
271248
if (locale === this.config.sourceLocale) {
272249
// For source locale, just return the (possibly pluralized) sourceText
273250
this.logger.debug(
274-
`[TRACE] Source locale detected, returning sourceText for ${hashesNeedingTranslation.length} entries`,
251+
`Source locale detected, returning sourceText for ${hashesNeedingTranslation.length} entries`,
275252
);
276253
for (const [hash, entry] of Object.entries(entriesToTranslate)) {
277254
newTranslations[hash] = entry.text;
@@ -280,30 +257,16 @@ export class TranslationService {
280257
// For other locales, translate only entries without overrides
281258
try {
282259
this.logger.debug(
283-
`[TRACE] Calling translator.translate() for ${locale} with ${Object.keys(entriesToTranslate).length} entries`,
260+
`Translating ${locale} with ${Object.keys(entriesToTranslate).length} entries`,
284261
);
285-
this.logger.debug(`[TRACE] About to await translator.translate()...`);
286-
const translateStartTime = performance.now();
287-
this.logger.debug(`[TRACE] Executing translator.translate() NOW`);
288262
const translatedTexts = await this.translator.translate(
289263
locale,
290264
entriesToTranslate,
291265
);
292-
this.logger.debug(`[TRACE] translator.translate() returned`);
293-
294266
// Merge translated texts with overridden translations
295267
newTranslations = { ...overriddenTranslations, ...translatedTexts };
296-
297-
const translateEndTime = performance.now();
298-
this.logger.debug(
299-
`[TRACE] translator.translate() completed in ${(translateEndTime - translateStartTime).toFixed(2)}ms`,
300-
);
301-
this.logger.debug(
302-
`[TRACE] Received ${Object.keys(translatedTexts).length} translations (+ ${overrideCount} overrides)`,
303-
);
304268
} catch (error) {
305-
// Complete failure - log and return what we have from cache
306-
this.logger.error(`Translation failed completely:`, error);
269+
this.logger.error(`Translation failed:`, error);
307270

308271
return {
309272
translations: this.pickTranslations(
@@ -336,7 +299,7 @@ export class TranslationService {
336299
errors.push({
337300
hash,
338301
sourceText: entry?.sourceText || "",
339-
error: "Translation not returned by translator",
302+
error: "Translator doesn't return translation",
340303
});
341304
}
342305
}
@@ -357,7 +320,7 @@ export class TranslationService {
357320
const result = this.pickTranslations(allTranslations, workingHashes);
358321

359322
const endTime = performance.now();
360-
this.logger.info(
323+
this.logger.debug(
361324
`Translation completed for ${locale}: ${Object.keys(newTranslations).length} new, ${cachedCount} cached, ${errors.length} errors in ${(endTime - startTime).toFixed(2)}ms`,
362325
);
363326

0 commit comments

Comments
 (0)