Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to SLF4J for logging #1120

Merged
merged 5 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Changed

* Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116))

## [2.22.2] - 2022-02-09
### Changed
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).
Expand Down
1 change: 0 additions & 1 deletion gradle/javadoc/java8/package-list
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ java.util.concurrent.atomic
java.util.concurrent.locks
java.util.function
java.util.jar
java.util.logging
java.util.prefs
java.util.regex
java.util.spi
Expand Down
2 changes: 2 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ for (glue in NEEDS_GLUE) {
}

dependencies {
compileOnly 'org.slf4j:slf4j-api:1.7.35'
// zero runtime reqs is a hard requirements for spotless-lib
// if you need a dep, put it in lib-extra
testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT"
Expand All @@ -29,6 +30,7 @@ dependencies {

// used for pom sorting
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0'
sortPomCompileOnly 'org.slf4j:slf4j-api:1.7.35'

palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2021-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import com.pinterest.ktlint.core.KtLint;
import com.pinterest.ktlint.core.KtLint.Params;
Expand All @@ -33,7 +32,6 @@
import kotlin.jvm.functions.Function2;

public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {
private static final Logger logger = Logger.getLogger(KtlintFormatterFunc.class.getName());

private final List<RuleSet> rulesets;
private final Map<String, String> userData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,13 +15,13 @@
*/
package com.diffplug.spotless;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class FormatExceptionPolicyLegacy extends NoLambda.EqualityBasedOnSerialization implements FormatExceptionPolicy {
private static final long serialVersionUID = 1L;

private static final Logger logger = Logger.getLogger(Formatter.class.getName());
private static final Logger logger = LoggerFactory.getLogger(Formatter.class);

@Override
public void handleError(Throwable e, FormatterStep step, String relativePath) {
Expand All @@ -34,10 +34,10 @@ public void handleError(Throwable e, FormatterStep step, String relativePath) {
}

static void error(Throwable e, FormatterStep step, String relativePath) {
logger.log(Level.SEVERE, "Step '" + step.getName() + "' found problem in '" + relativePath + "':\n" + e.getMessage(), e);
logger.error("Step '{}' found problem in '{}':\n{}", step.getName(), relativePath, e.getMessage(), e);
}

static void warning(Throwable e, FormatterStep step, String relativePath) {
logger.log(Level.WARNING, "Unable to apply step '" + step.getName() + "' to '" + relativePath + "'", e);
logger.warn("Unable to apply step '{}' to '{}'", step.getName(), relativePath, e);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,9 @@
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.logging.Logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
Expand Down Expand Up @@ -78,8 +80,8 @@ private static class State implements Serializable {
}

FormatterFunc createFormat() throws Exception {
Logger logger = Logger.getLogger(FreshMarkStep.class.getName());
Consumer<String> loggingStream = logger::warning;
Logger logger = LoggerFactory.getLogger(FreshMarkStep.class);
Consumer<String> loggingStream = logger::warn;

ClassLoader classLoader = jarState.getClassLoader();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,9 @@
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.FormatterFunc;
Expand All @@ -36,7 +38,7 @@

abstract class NpmFormatterStepStateBase implements Serializable {

private static final Logger logger = Logger.getLogger(NpmFormatterStepStateBase.class.getName());
private static final Logger logger = LoggerFactory.getLogger(NpmFormatterStepStateBase.class);

private static final long serialVersionUID = 1460749955865959948L;

Expand Down Expand Up @@ -166,13 +168,15 @@ public String getBaseUrl() {
@Override
public void close() throws Exception {
try {
logger.fine("Closing npm server in directory <" + serverPortFile.getParent() + "> and port <" + serverPort + ">");
logger.trace("Closing npm server in directory <{}> and port <{}>",
serverPortFile.getParent(), serverPort);

if (server.isAlive()) {
boolean ended = server.waitFor(5, TimeUnit.SECONDS);
if (!ended) {
logger.info("Force-Closing npm server in directory <" + serverPortFile.getParent() + "> and port <" + serverPort + ">");
logger.info("Force-Closing npm server in directory <{}> and port <{}>", serverPortFile.getParent(), serverPort);
server.destroyForcibly().waitFor();
logger.fine("Force-Closing npm server in directory <" + serverPortFile.getParent() + "> and port <" + serverPort + "> -- Finished");
logger.trace("Force-Closing npm server in directory <{}> and port <{}> -- Finished", serverPortFile.getParent(), serverPort);
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,11 +23,12 @@
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterFunc.Closeable;
import com.diffplug.spotless.FormatterStep;
Expand All @@ -36,7 +37,7 @@

public class PrettierFormatterStep {

private static final Logger logger = Logger.getLogger(PrettierFormatterStep.class.getName());
private static final Logger logger = LoggerFactory.getLogger(PrettierFormatterStep.class);

public static final String NAME = "prettier-format";

Expand Down Expand Up @@ -95,7 +96,7 @@ private void endServer(PrettierRestService restService, ServerProcessInfo restSe
try {
restService.shutdown();
} catch (Throwable t) {
logger.log(Level.INFO, "Failed to request shutdown of rest service via api. Trying via process.", t);
logger.info("Failed to request shutdown of rest service via api. Trying via process.", t);
}
restServer.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,12 +21,13 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterFunc.Closeable;
import com.diffplug.spotless.FormatterStep;
Expand All @@ -35,7 +36,7 @@

public class TsFmtFormatterStep {

private static final Logger logger = Logger.getLogger(TsFmtFormatterStep.class.getName());
private static final Logger logger = LoggerFactory.getLogger(TsFmtFormatterStep.class);

public static final String NAME = "tsfmt-format";

Expand Down Expand Up @@ -115,7 +116,7 @@ private void endServer(TsFmtRestService restService, ServerProcessInfo restServe
try {
restService.shutdown();
} catch (Throwable t) {
logger.log(Level.INFO, "Failed to request shutdown of rest service via api. Trying via process.", t);
logger.info("Failed to request shutdown of rest service via api. Trying via process.", t);
}
restServer.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2021-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,9 +18,10 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.logging.Logger;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.pom.SortPomCfg;
Expand All @@ -30,7 +31,7 @@
import sortpom.parameter.PluginParameters;

public class SortPomFormatterFunc implements FormatterFunc {
private static final Logger logger = Logger.getLogger(SortPomFormatterFunc.class.getName());
private static final Logger logger = LoggerFactory.getLogger(SortPomFormatterFunc.class);
private final SortPomCfg cfg;

public SortPomFormatterFunc(SortPomCfg cfg) {
Expand Down Expand Up @@ -61,7 +62,7 @@ public String apply(String input) throws Exception {
private static class MySortPomLogger implements SortPomLogger {
@Override
public void warn(String content) {
logger.warning(content);
logger.warn(content);
}

@Override
Expand All @@ -71,7 +72,7 @@ public void info(String content) {

@Override
public void error(String content) {
logger.severe(content);
logger.error(content);
}
}
}
4 changes: 4 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Changed

* Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116))

## [6.2.2] - 2022-02-09
### Changed
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,8 +20,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.gradle.api.GradleException;
import org.gradle.api.Project;
Expand All @@ -30,6 +28,8 @@
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.attributes.Bundling;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.common.base.Unhandled;
import com.diffplug.common.collect.ImmutableList;
Expand Down Expand Up @@ -127,17 +127,17 @@ private static Provisioner forConfigurationContainer(Project project, Configurat
if (!projName.isEmpty()) {
projName = projName + "/";
}
logger.log(
Level.SEVERE,
"You need to add a repository containing the '" + mavenCoords + "' artifact in '" + projName + "build.gradle'.\n" +
logger.error(
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps use a {} placeholder here instead of mavenCoords

"You need to add a repository containing the '{}' artifact in '{}build.gradle'.\n" +
"E.g.: 'repositories { mavenCentral() }'",
mavenCoords, projName,
e);
throw e;
}
};
}

private static final Logger logger = Logger.getLogger(GradleProvisioner.class.getName());
private static final Logger logger = LoggerFactory.getLogger(GradleProvisioner.class);

/** Models a request to the provisioner. */
private static class Request {
Expand Down
4 changes: 4 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Changed

* Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116))

## [2.20.2] - 2022-02-09
### Changed
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).
Expand Down