Skip to content

Commit cf531d4

Browse files
CopilotGoooler
andauthored
Prefer parameterized logging (#1977)
* Initial plan * Replace string templates with {} placeholder styles for logging Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com> Co-authored-by: Zongle Wang <wangzongler@gmail.com>
1 parent 85ba389 commit cf531d4

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
8282
afterEvaluate {
8383
if (shadow.addTargetJvmVersionAttribute.get()) {
8484
logger.info(
85-
"Setting ${TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE.name} attribute for ${shadowRuntimeElements.name} configuration."
85+
"Setting {} attribute for {} configuration.",
86+
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE.name,
87+
shadowRuntimeElements.name,
8688
)
8789
} else {
8890
logger.info(
89-
"Skipping setting ${TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE.name} attribute for ${shadowRuntimeElements.name} configuration."
91+
"Skipping setting {} attribute for {} configuration.",
92+
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE.name,
93+
shadowRuntimeElements.name,
9094
)
9195
return@afterEvaluate
9296
}
@@ -105,7 +109,9 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
105109
)
106110
} else {
107111
logger.info(
108-
"Setting target JVM version to $targetJvmVersion for ${shadowRuntimeElements.name} configuration."
112+
"Setting target JVM version to {} for {} configuration.",
113+
targetJvmVersion,
114+
shadowRuntimeElements.name,
109115
)
110116
shadowRuntimeElements.configure {
111117
it.attributes { attrs ->
@@ -127,9 +133,9 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
127133
// addShadowVariantIntoJavaComponent.
128134
afterEvaluate {
129135
if (shadow.addShadowVariantIntoJavaComponent.get()) {
130-
logger.info("Adding ${shadowRuntimeElements.name} variant to Java component.")
136+
logger.info("Adding {} variant to Java component.", shadowRuntimeElements.name)
131137
} else {
132-
logger.info("Skipping adding ${shadowRuntimeElements.name} variant to Java component.")
138+
logger.info("Skipping adding {} variant to Java component.", shadowRuntimeElements.name)
133139
return@afterEvaluate
134140
}
135141
components.named("java", AdhocComponentWithVariants::class.java) {

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowKmpPlugin.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public abstract class ShadowKmpPlugin : Plugin<Project> {
2121
// Declaring multiple Kotlin Targets of the same type is not supported. See
2222
// https://kotl.in/declaring-multiple-targets for more details.
2323
logger.info(
24-
"$SHADOW_JAR_TASK_NAME task already exists, skipping configuration for target: ${target.name}"
24+
"{} task already exists, skipping configuration for target: {}",
25+
SHADOW_JAR_TASK_NAME,
26+
target.name,
2527
)
2628
return@configureEach
2729
}

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ constructor(
148148
private inner class StreamAction(private val zipOutStr: ZipOutputStream) :
149149
CopyActionProcessingStreamAction {
150150
init {
151-
logger.info("Relocator count: ${relocators.size}.")
151+
logger.info("Relocator count: {}.", relocators.size)
152152
if (encoding != null) {
153153
zipOutStr.setEncoding(encoding)
154154
}
@@ -202,7 +202,7 @@ constructor(
202202
val className = classPath.substringBeforeLast(".").replace('/', '.')
203203
return unusedClasses.contains(className).also {
204204
if (it) {
205-
logger.info("Dropping unused class: $className")
205+
logger.info("Dropping unused class: {}", className)
206206
}
207207
}
208208
}

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ public abstract class ShadowJar : Jar() {
543543
get() {
544544
if (enableAutoRelocation.get()) {
545545
logger.info(
546-
"Adding auto relocation packages in the dependencies with prefix '${relocationPrefix.get()}'."
546+
"Adding auto relocation packages in the dependencies with prefix '{}'.",
547+
relocationPrefix.get(),
547548
)
548549
} else {
549550
logger.info("Skipping package relocators as auto relocation is disabled.")
@@ -568,18 +569,22 @@ public abstract class ShadowJar : Jar() {
568569
when {
569570
manifest.attributes.contains(mainClassAttributeKey) -> {
570571
logger.info(
571-
"Skipping adding $mainClassAttributeKey attribute to the manifest as it is already set."
572+
"Skipping adding {} attribute to the manifest as it is already set.",
573+
mainClassAttributeKey,
572574
)
573575
}
574576
mainClassValue.isNullOrEmpty() -> {
575577
logger.info(
576-
"Skipping adding $mainClassAttributeKey attribute to the manifest as it is empty."
578+
"Skipping adding {} attribute to the manifest as it is empty.",
579+
mainClassAttributeKey,
577580
)
578581
}
579582
else -> {
580583
manifest.attributes[mainClassAttributeKey] = mainClassValue
581584
logger.info(
582-
"Adding $mainClassAttributeKey attribute to the manifest with value '$mainClassValue'."
585+
"Adding {} attribute to the manifest with value '{}'.",
586+
mainClassAttributeKey,
587+
mainClassValue,
583588
)
584589
}
585590
}
@@ -593,11 +598,13 @@ public abstract class ShadowJar : Jar() {
593598

594599
if (addMultiReleaseAttribute.get()) {
595600
logger.info(
596-
"Adding $multiReleaseAttributeKey attribute to the manifest if any dependencies contain it."
601+
"Adding {} attribute to the manifest if any dependencies contain it.",
602+
multiReleaseAttributeKey,
597603
)
598604
} else {
599605
logger.info(
600-
"Skipping adding $multiReleaseAttributeKey attribute to the manifest as it is disabled."
606+
"Skipping adding {} attribute to the manifest as it is disabled.",
607+
multiReleaseAttributeKey,
601608
)
602609
return
603610
}

0 commit comments

Comments
 (0)