Skip to content

refactor: migrate remaining console.log in lint.ts to scoped logger - #43

Closed
luandro wants to merge 2 commits into
mainfrom
fix/35-lint-scoped-logger
Closed

luandro wants to merge 2 commits into
mainfrom
fix/35-lint-scoped-logger

Conversation

@luandro

@luandro luandro commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

src/lint.ts had ~50 console.log/console.warn/console.error/console.time calls mixed with getScopedLogger() calls. The rest of the codebase has been fully migrated to scoped logging.

Changes

Replaced all non-test console.* calls with appropriate getScopedLogger() calls across 17 functions:

  • LintWhitespace — cleanWhitespaceOnlyCells
  • LintDuplicates — checkForDuplicates
  • LintUnreferencedDetails — checkUnreferencedDetails
  • LintDetails — validateUniversalFlag, lintDetailsSheet
  • LintTranslationSlugs — checkDuplicateTranslationSlugs
  • LintTranslationHeaders — validateTranslationHeaders
  • LintSheet — lintSheet
  • LintCategoryIcons — validateCategoryIcons
  • LintCategories — lintCategoriesSheet
  • LintTranslationSourceOverwrites — checkTranslationSourceOverwrites
  • LintTranslations — lintTranslationSheets
  • LintTranslationConsistency — validateTranslationSheetConsistency, validateSheetConsistency
  • LintDialogHtml — validateDialogHtml
  • LintFixTranslationSheets — fixTranslationMismatches
  • LintAllSheets — lintAllSheets

Log level mapping

  • Starting/completing operations → logger.info
  • Warnings/edge cases → logger.warn
  • Errors → logger.error
  • Debug details → logger.debug
  • console.time/console.timeEnd → logger.debug (GAS does not support console.time)

Not modified

  • Test functions (testHtmlValidation, testDialogHtmlGeneration, runAllHtmlValidationTests) — intentional test output preserved

No behavior changes. Pure logging migration.

Closes #35

Greptile Summary

This PR migrates all remaining console.log/console.warn/console.error/console.time calls in src/lint.ts to the project's getScopedLogger() API, completing the codebase-wide structured logging migration. Log level mapping follows the documented convention (info for lifecycle events, warn for edge cases, error for failures, debug for detail/former timing markers).

  • 17 functions updated across the lint pipeline, each receiving a scoped logger (mostly hoisted to the function entry point) so log output carries a consistent [ScopeName] prefix.
  • console.time/console.timeEnd pairs removed in lintSheet (including the finally block) and replaced with logger.debug start markers; GAS does not support console.time, making this a correctness improvement on that runtime.
  • Test helper functions left untouched, preserving intentional console.* output in testHtmlValidation, testDialogHtmlGeneration, and runAllHtmlValidationTests.

Confidence Score: 4/5

Safe to merge; this is a pure logging substitution with no changes to lint logic, sheet mutations, or return values.

All 17 functions are cleanly migrated and logger placement is correct at function entry in the vast majority of cases. An open thread from a prior review notes that the logger in checkDuplicateTranslationSlugs is created inside the inner column loop, making it technically out of scope for the catch block — that remains unresolved in this version. No other logic is touched.

src/lint.ts — specifically the checkDuplicateTranslationSlugs function where the logger scope concern from the prior review is still open.

Important Files Changed

Filename Overview
src/lint.ts Pure logging refactor replacing ~50 console.* calls with getScopedLogger(); logger placement is correct at function entry in most cases, with two pre-existing scope-placement concerns already flagged in earlier review threads.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[lint.ts function called] --> B[getScopedLogger at function entry]
    B --> C{Operation type}
    C -->|lifecycle start/end| D[logger.info]
    C -->|edge case or empty sheet| E[logger.warn]
    C -->|exception caught| F[logger.error]
    C -->|diagnostic detail or former console.time| G[logger.debug]
    D --> H[AppAppLogger.scope prepends ScopeName]
    E --> H
    F --> H
    G --> H
    H --> I[console.log / console.warn / console.error via AppAppLogger.output]
Loading

Comments Outside Diff (1)

  1. src/lint.ts, line 1370-1379 (link)

    P2 The logger is created separately in three different scopes inside checkUnreferencedDetails — once inside the early-exit if, once inside the for loop on every unreferenced entry, and once in the catch block. The per-iteration instantiation in the loop is the main concern: when AppLogger is live, scope() allocates a new logger object on each call. Hoist a single getScopedLogger("LintUnreferencedDetails") call to the top of the function.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/lint.ts
    Line: 1370-1379
    
    Comment:
    The logger is created separately in three different scopes inside `checkUnreferencedDetails` — once inside the early-exit `if`, once inside the `for` loop on every unreferenced entry, and once in the `catch` block. The per-iteration instantiation in the loop is the main concern: when `AppLogger` is live, `scope()` allocates a new logger object on each call. Hoist a single `getScopedLogger("LintUnreferencedDetails")` call to the top of the function.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (2): Last reviewed commit: "refactor: hoist getScopedLogger calls ou..." | Re-trigger Greptile

Replace ~50 console.log/warn/error/time calls with getScopedLogger()
across 17 functions in lint.ts. Test functions intentionally preserved.

Scopes added: LintWhitespace, LintDuplicates, LintUnreferencedDetails,
LintDetails, LintTranslationSlugs, LintTranslationHeaders, LintSheet,
LintCategoryIcons, LintCategories, LintTranslationSourceOverwrites,
LintTranslations, LintTranslationConsistency, LintDialogHtml,
LintFixTranslationSheets, LintAllSheets.

Closes #35
@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Migrate remaining console logging to scoped logger in lint.ts

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Migrated ~50 console.log/warn/error/time calls to scoped logger
• Replaced console.time/timeEnd with logger.debug calls across 15 functions
• Applied appropriate log levels: info for operations, warn for edge cases, error for failures,
  debug for details
• Test functions intentionally preserved to maintain test output behavior
Diagram
flowchart LR
  A["console.log/warn/error/time calls"] -->|"Replace with getScopedLogger"| B["Scoped logger instances"]
  B -->|"Map log levels"| C["info/warn/error/debug"]
  C -->|"Applied to 15 functions"| D["Linting functions"]
  D -->|"Preserve test output"| E["Test functions unchanged"]

Loading

Grey Divider

File Changes

1. src/lint.ts ✨ Enhancement +91/-78

Migrate console logging to scoped logger throughout

• Replaced all console.log/warn/error calls with getScopedLogger() across 15 linting functions
• Removed console.time/timeEnd calls and replaced with logger.debug for operation tracking
• Applied consistent log level mapping: info for operations, warn for warnings, error for errors,
 debug for details
• Test functions (testHtmlValidation, testDialogHtmlGeneration, runAllHtmlValidationTests)
 intentionally preserved
• Functions updated: cleanWhitespaceOnlyCells, checkForDuplicates, checkUnreferencedDetails,
 validateUniversalFlag, checkDuplicateTranslationSlugs, validateTranslationHeaders, lintSheet,
 validateCategoryIcons, lintCategoriesSheet, lintDetailsSheet, checkTranslationSourceOverwrites,
 lintTranslationSheets, validateTranslationSheetConsistency, validateSheetConsistency,
 validateDialogHtml, fixTranslationMismatches, lintAllSheets

src/lint.ts


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0)

Grey Divider


Remediation recommended

1. checkUnreferencedDetails recreates logger ✓ Resolved 📘 Rule violation ◔ Observability
Description
getScopedLogger(...) is called multiple times within the same functions and even inside per-item
loops (e.g., per unreferenced entry or per duplicate slug) instead of reusing a single scoped logger
instance. This violates the requirement to reuse scoped loggers and introduces avoidable
overhead/allocations and logging-pattern noise in potentially hot paths (e.g., large sheets).
Code

src/lint.ts[R1378-1379]

Evidence
PR Compliance ID 342705 requires that a scoped logger be obtained once for a scope and reused rather
than recreated repeatedly. The cited regions in src/lint.ts show `const logger =
getScopedLogger("...") being instantiated multiple times within checkUnreferencedDetails()`
(including inside a loop) and within checkDuplicateTranslationSlugs() (inside an inner loop and
again in a catch), which means the same scope’s logger is not reused within the function.
Additionally, because getScopedLogger() only caches the fallback logger and the
AppLogger/AppAppLogger .scope() path returns a new scoped logger object each time, repeated
calls inside loops can create many temporary logger objects unnecessarily.

Rule 342705: Use getScopedLogger() instead of direct Logger.log calls
src/lint.ts[1313-1314]
src/lint.ts[1378-1379]
src/lint.ts[1391-1392]
src/lint.ts[1471-1474]
src/lint.ts[1487-1488]
src/lint.ts[1370-1384]
src/lint.ts[1468-1474]
src/loggingHelpers.ts[36-54]
src/logger.ts[277-293]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`getScopedLogger()` is invoked repeatedly within the same function and inside tight loops (e.g., per unreferenced detail and per duplicate slug), creating multiple scoped logger instances for the same scope.

## Issue Context
PR Compliance ID 342705 requires that a scoped logger is obtained via `getScopedLogger()` and then reused within the module/function (or appropriate outer scope like per sheet) rather than recreated at each log site. This is particularly important because `getScopedLogger()` only caches the fallback logger, while the `AppLogger.scope()` / `AppAppLogger.scope()` path is not cached and returns a fresh scoped logger object on each call, so calling it repeatedly inside loops adds avoidable allocations and work.

## Fix Focus Areas
- src/lint.ts[1310-1393]
- src/lint.ts[1465-1484]
- src/lint.ts[1313-1322]
- src/lint.ts[1378-1387]
- src/lint.ts[1391-1392]
- src/lint.ts[1471-1474]
- src/lint.ts[1487-1488]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread src/lint.ts Resolved
Greptile review feedback: logger was instantiated per-iteration inside
for loops and in catch blocks, despite already being hoisted to function
top in checkUnreferencedDetails. Removed 4 redundant getScopedLogger
calls across checkUnreferencedDetails and checkDuplicateTranslationSlugs.
luandro added a commit that referenced this pull request Jun 4, 2026
Apply scoped logger migration to the split lint module files.
Replaces console.log/warn/error/time with getScopedLogger() calls
across 6 files (73 replacements total).

Test functions intentionally preserved.

This makes PR #43 (fix/35-lint-scoped-logger) redundant since the
logger migration is now included in the lint split.
@luandro

luandro commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by PR #46 which now includes both the lint split AND the scoped logger migration. No need for a separate PR.

@luandro luandro closed this Jun 4, 2026
luandro added a commit that referenced this pull request Jun 6, 2026
Apply scoped logger migration to the split lint module files.
Replaces console.log/warn/error/time with getScopedLogger() calls
across 6 files (73 replacements total).

Test functions intentionally preserved.

This makes PR #43 (fix/35-lint-scoped-logger) redundant since the
logger migration is now included in the lint split.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate remaining console.log calls in lint.ts to scoped logger

1 participant