Conversation
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>
There was a problem hiding this comment.
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(", ")}") |
There was a problem hiding this comment.
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.
| logger.info(s"Self-ref constraints for $tableName: ${selfRefFks.flatMap(_.fkName).mkString(", ")}") | |
| logger.info( | |
| "Self-ref constraints for {}: {}", | |
| tableName, | |
| selfRefFks.flatMap(_.fkName).mkString(", ") | |
| ) |
| 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...") | ||
|
|
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Same concern as other changes: string interpolation eagerly builds the message even when WARN is disabled. SLF4J {} placeholders (or logger.isWarnEnabled) keep formatting lazy.
| 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 |
There was a problem hiding this comment.
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.
| 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) => |
There was a problem hiding this comment.
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.
| 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") |
There was a problem hiding this comment.
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.
| 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") |
There was a problem hiding this comment.
Same concern as above: interpolation eagerly formats the message even when INFO is disabled. With SLF4J, prefer parameterized logging ({} placeholders) or an isInfoEnabled guard.
| 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(", ")}") |
There was a problem hiding this comment.
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.
| val tableName = table.name.name | ||
| if (skippedTables.contains(tableName)) { | ||
| logger.info("Skipping table: {}", tableName) | ||
| logger.info(s"Skipping table: $tableName") |
There was a problem hiding this comment.
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.
| logger.info(s"Skipping table: $tableName") | |
| logger.info("Skipping table: {}", tableName) |
Summary
{}placeholder logging with Scalas"..."string interpolation across 7 filesTest plan
bleep compilepasses (both Scala 2.13 and Scala 3)bleep fmtpasses🤖 Generated with Claude Code