Skip to content

Use Scala string interpolation for log messages#20

Open
nafg wants to merge 1 commit intomasterfrom
master-wt-6012
Open

Use Scala string interpolation for log messages#20
nafg wants to merge 1 commit intomasterfrom
master-wt-6012

Conversation

@nafg
Copy link
Collaborator

@nafg nafg commented Feb 12, 2026

Summary

  • Replace SLF4J {} placeholder logging with Scala s"..." string interpolation across 7 files
  • More idiomatic Scala style while preserving identical log output

Test plan

  • bleep compile passes (both Scala 2.13 and Scala 3)
  • bleep fmt passes

🤖 Generated with Claude Code

Replace SLF4J {} placeholders with Scala s"..." string interpolation
across all logger calls for more idiomatic Scala code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates logging calls in the simple-anonymizer module to use Scala s"..." string interpolation instead of SLF4J {}-style parameterized messages.

Changes:

  • Replaced SLF4J {} placeholder usage with Scala string interpolation in log messages.
  • Updated log statements across table sorting/copying, DB context metadata fetching, and JSON lens warnings.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
simple-anonymizer/src/scala/simpleanonymizer/TableSorter.scala Updates circular-dependency warning log formatting.
simple-anonymizer/src/scala/simpleanonymizer/TableCopier.scala Updates info logs for transformed columns and sequence resets.
simple-anonymizer/src/scala/simpleanonymizer/SelfRefConstraints.scala Updates info log for detected self-referential constraints.
simple-anonymizer/src/scala/simpleanonymizer/Lens.scala Updates warn logs for JSON parsing/type mismatch and missing fields.
simple-anonymizer/src/scala/simpleanonymizer/DbCopier.scala Updates info logs for copy orchestration and skipped tables.
simple-anonymizer/src/scala/simpleanonymizer/DbContext.scala Updates info logs for schema metadata discovery counts.
simple-anonymizer/src/scala/simpleanonymizer/CopyAction.scala Updates debug/info logs for SQL visibility and copy progress.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (selfRefFks.nonEmpty)
logger.info("Self-ref constraints for {}: {}", tableName, selfRefFks.flatMap(_.fkName).mkString(", "))
logger.info(s"Self-ref constraints for $tableName: ${selfRefFks.flatMap(_.fkName).mkString(", ")}")
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switches from SLF4J parameterized logging to Scala interpolation. Interpolation constructs the final INFO message string before the logger can check whether INFO is enabled; parameterized logging avoids that formatting/allocation when INFO is off. Consider reverting to {} placeholders (or guarding with logger.isInfoEnabled) to preserve SLF4J’s lazy formatting behavior.

Suggested change
logger.info(s"Self-ref constraints for $tableName: ${selfRefFks.flatMap(_.fkName).mkString(", ")}")
logger.info(
"Self-ref constraints for {}: {}",
tableName,
selfRefFks.flatMap(_.fkName).mkString(", ")
)

Copilot uses AI. Check for mistakes.
Comment on lines 58 to 60
val totalTables = levels.map(_.size).sum
logger.info("Copying {} tables in {} levels...", totalTables, levels.size)
logger.info(s"Copying $totalTables tables in ${levels.size} levels...")

Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using s"..." here eagerly formats the message even when INFO is disabled. With SLF4J, prefer parameterized logging or guard with logger.isInfoEnabled to avoid unnecessary allocations.

Copilot uses AI. Check for mistakes.
Comment on lines 93 to 97
val transformed = inner.modifyJson(f)(fieldValue)
obj.add(fieldName, transformed).asJson
case None =>
logger.warn("Field '{}' not found in JSON object", fieldName)
logger.warn(s"Field '$fieldName' not found in JSON object")
json
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message is now eagerly formatted even if WARN logging is disabled. With SLF4J, keep parameterized logging or guard with logger.isWarnEnabled to avoid doing work on disabled log levels.

Copilot uses AI. Check for mistakes.
Comment on lines 109 to 113
protected def modifyJson(f: String => String): Json => Json = { json =>
json.asArray match {
case None =>
logger.warn("Expected array but got {}", json.name)
logger.warn(s"Expected array but got ${json.name}")
json
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as other changes: string interpolation eagerly builds the message even when WARN is disabled. SLF4J {} placeholders (or logger.isWarnEnabled) keep formatting lazy.

Copilot uses AI. Check for mistakes.
Comment on lines 26 to 29
MTable.getTables(None, Some(schema), None, Some(Seq("TABLE"))).map(_.sortBy(_.name.name))
).map { tables =>
logger.info("Found {} tables.", tables.size)
logger.info(s"Found ${tables.size} tables.")
tables
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to string interpolation causes eager message construction even when INFO is disabled. With org.slf4j loggers, prefer {} placeholders (or logger.isInfoEnabled) to preserve SLF4J’s lazy formatting behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 86 to 90
json.asObject match {
case None =>
logger.warn("Expected object but got {}", json.name)
logger.warn(s"Expected object but got ${json.name}")
json
case Some(obj) =>
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String interpolation here removes SLF4J’s lazy formatting; the message is built even if WARN is disabled. Prefer {} placeholders (or a logger.isWarnEnabled guard) for consistency and to avoid unnecessary work.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +85
logger.debug(s"SELECT: $selectSql")

val totalRowsFut = sourceDbContext.db.run(sql"SELECT count(*) FROM (#$selectSql) t".as[Int].head)
totalRowsFut.foreach(n => logger.info("Table {} has {} rows", tableName, n))
logger.info("Copying table: {}", tableName)
totalRowsFut.foreach(n => logger.info(s"Table $tableName has $n rows"))
logger.info(s"Copying table: $tableName")
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using string interpolation for SLF4J logging eagerly builds the message even when DEBUG/INFO is disabled. Consider reverting to parameterized logging ({} placeholders) or adding isDebugEnabled/isInfoEnabled guards, especially for potentially expensive values like SQL strings.

Copilot uses AI. Check for mistakes.
Comment on lines 223 to +226
try {
if (buffer.nonEmpty)
count += insertBatch(buffer.toVector)
logger.info("Copied {}{} rows from {}", count, totalSuffix, quotedTable)
logger.info(s"Copied $count$totalSuffix rows from $quotedTable")
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as above: interpolation eagerly formats the message even when INFO is disabled. With SLF4J, prefer parameterized logging ({} placeholders) or an isInfoEnabled guard.

Copilot uses AI. Check for mistakes.
Comment on lines 44 to +46
val transformedColumns = tableSpec.columns.collect { case c if !c.isInstanceOf[OutputColumn.SourceColumn] => c.name }
if (transformedColumns.nonEmpty)
logger.info("Transforming columns of {}: {}", tableName, transformedColumns.mkString(", "))
logger.info(s"Transforming columns of $tableName: ${transformedColumns.mkString(", ")}")
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Scala string interpolation with an org.slf4j logger eagerly constructs the final INFO message string even when INFO is disabled. SLF4J’s parameterized logging ({} placeholders) avoids formatting/allocation work when the level is off, so it’s usually preferable unless you explicitly guard with logger.isInfoEnabled.

Copilot uses AI. Check for mistakes.
val tableName = table.name.name
if (skippedTables.contains(tableName)) {
logger.info("Skipping table: {}", tableName)
logger.info(s"Skipping table: $tableName")
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is now built eagerly even if INFO is disabled. Consider keeping SLF4J parameterized logging (logger.info("Skipping table: {}", tableName)) or adding an isInfoEnabled guard.

Suggested change
logger.info(s"Skipping table: $tableName")
logger.info("Skipping table: {}", tableName)

Copilot uses AI. Check for mistakes.
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.

1 participant

Comments