Skip to content

Commit 05b8779

Browse files
authored
Switch from System.err to SLF4J (#1554)
2 parents e19c156 + 46cb7e6 commit 05b8779

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,8 @@
4242
import org.eclipse.jgit.storage.file.FileBasedConfig;
4343
import org.eclipse.jgit.util.FS;
4444
import org.eclipse.jgit.util.SystemReader;
45+
import org.slf4j.Logger;
46+
import org.slf4j.LoggerFactory;
4547

4648
import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree;
4749
import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory;
@@ -61,6 +63,8 @@
6163
* back to the platform native.
6264
*/
6365
public final class GitAttributesLineEndings {
66+
private static final Logger LOGGER = LoggerFactory.getLogger(GitAttributesLineEndings.class);
67+
6468
// prevent direct instantiation
6569
private GitAttributesLineEndings() {}
6670

@@ -261,7 +265,7 @@ private static String convertEolToLineEnding(String eol, File file) {
261265
case "crlf":
262266
return LineEnding.WINDOWS.str();
263267
default:
264-
System.err.println(".gitattributes file has unspecified eol value: " + eol + " for " + file + ", defaulting to platform native");
268+
LOGGER.warn(".gitattributes file has unspecified eol value: {} for {}, defaulting to platform native", eol, file);
265269
return LineEnding.PLATFORM_NATIVE.str();
266270
}
267271
}
@@ -341,8 +345,7 @@ private static List<AttributesRule> parseRules(@Nullable File file) {
341345
return parsed.getRules();
342346
} catch (IOException e) {
343347
// no need to crash the whole plugin
344-
System.err.println("Problem parsing " + file.getAbsolutePath());
345-
e.printStackTrace();
348+
LOGGER.warn("Problem parsing {}", file.getAbsolutePath(), e);
346349
}
347350
}
348351
return Collections.emptyList();

lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
import javax.annotation.Nullable;
3333

34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
36+
3437
import com.diffplug.spotless.FileSignature;
3538
import com.diffplug.spotless.FormatterFunc;
3639
import com.diffplug.spotless.FormatterStep;
@@ -42,6 +45,8 @@
4245

4346
/** Prefixes a license header before the package statement. */
4447
public final class LicenseHeaderStep {
48+
private static final Logger LOGGER = LoggerFactory.getLogger(LicenseHeaderStep.class);
49+
4550
public enum YearMode {
4651
PRESERVE, UPDATE_TO_TODAY, SET_FROM_GIT
4752
}
@@ -381,7 +386,7 @@ private String calculateYearBySearching(String content) {
381386
}
382387
}
383388
} else {
384-
System.err.println("Can't parse copyright year '" + content + "', defaulting to " + yearToday);
389+
LOGGER.warn("Can't parse copyright year '{}', defaulting to {}", content, yearToday);
385390
// couldn't recognize the year format
386391
return yearToday;
387392
}

lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,12 +28,17 @@
2828

2929
import javax.annotation.Nullable;
3030

31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
33+
3134
import com.diffplug.spotless.Jvm;
3235

3336
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3437
import sun.misc.Unsafe;
3538

3639
final class ModuleHelper {
40+
private static final Logger LOGGER = LoggerFactory.getLogger(ModuleHelper.class);
41+
3742
// prevent direct instantiation
3843
private ModuleHelper() {}
3944

@@ -66,11 +71,11 @@ public static synchronized void doOpenInternalPackagesIfRequired() {
6671
for (String name : failedToOpen) {
6772
message.append(String.format("--add-opens jdk.compiler/%s=ALL-UNNAMED", name));
6873
}
69-
System.err.println(message);
74+
LOGGER.warn("{}", message);
7075
}
7176
}
7277
} catch (Throwable e) {
73-
System.err.println("WARNING: Failed to check for unavailable JDK packages. Reason: " + e.getMessage());
78+
LOGGER.error("WARNING: Failed to check for available JDK packages.", e);
7479
}
7580
}
7681

0 commit comments

Comments
 (0)