Skip to content

Commit

Permalink
Use logging facade SLF4J instead of JDK Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Nov 6, 2023
1 parent 14fd04d commit 6c6f527
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
<scope>runtime</scope>
<scope>compile</scope>
</dependency>


Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/saucelabs/ci/BrowserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Handles invoking the Sauce REST API to retrieve the list of valid Browsers. The list of browser
Expand All @@ -22,7 +22,7 @@
*/
public class BrowserFactory {

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

public static final int ONE_HOUR_IN_MILLIS = 1000 * 60 * 60;

Expand Down Expand Up @@ -50,7 +50,7 @@ public BrowserFactory(SauceREST sauceREST) {
initializeWebDriverBrowsers();
initializeAppiumBrowsers();
} catch (JSONException | IOException e) {
logger.log(Level.WARNING, "Error retrieving browsers, attempting to continue", e);
LOGGER.warn("Error retrieving browsers, attempting to continue", e);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/saucelabs/ci/SODSeleniumConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author <a href="http://www.sysbliss.com">Jonathan Doklovic</a>
* @author Ross Rowe
*/
@Deprecated
public class SODSeleniumConfiguration {
private static final Logger logger = Logger.getLogger(SODSeleniumConfiguration.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(SODSeleniumConfiguration.class);

private String username;
private String accessKey;
Expand Down Expand Up @@ -157,7 +157,7 @@ public void setUserExtensions(JSONArray userExtensionsJson) {
this.userExtensions.add(ext);
} catch (JSONException e) {
// just print and ignore
logger.log(Level.WARNING, "Error parsing JSON string", e);
LOGGER.warn("Error parsing JSON string", e);
}
}
}
Expand All @@ -168,7 +168,7 @@ public void setUserExtensions(String jsonString) {
setUserExtensions(new JSONArray(jsonString));
} catch (JSONException e) {
// just print and ignore
logger.log(Level.WARNING, "Error parsing JSON string", e);
LOGGER.warn("Error parsing JSON string", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides common logic for the invocation of Sauce Connect v3 and v4 processes. The class
Expand All @@ -34,9 +35,7 @@
*/
public abstract class AbstractSauceTunnelManager implements SauceTunnelManager {

/** Logger instance. */
protected static final java.util.logging.Logger julLogger =
java.util.logging.Logger.getLogger(AbstractSauceTunnelManager.class.getName());
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractSauceTunnelManager.class);

/** Should Sauce Connect output be suppressed? */
protected boolean quietMode;
Expand Down Expand Up @@ -227,7 +226,7 @@ protected void logMessage(PrintStream printStream, String message) {
if (printStream != null) {
printStream.println(message);
}
julLogger.log(Level.INFO, message);
LOGGER.info(message);
}

/**
Expand Down Expand Up @@ -533,7 +532,7 @@ public Process openConnection(
}
} catch (InterruptedException e) {
// continue;
julLogger.log(Level.WARNING, "Exception occurred during invocation of Sauce Connect", e);
LOGGER.warn("Exception occurred during invocation of Sauce Connect", e);
}

incrementProcessCountForUser(tunnelInformation, printStream);
Expand Down Expand Up @@ -600,7 +599,7 @@ private String activeTunnelID(String username, String tunnelName) {
}
} catch (JSONException | IOException e) {
// log error and return false
julLogger.log(Level.WARNING, "Exception occurred retrieving tunnel information", e);
LOGGER.warn("Exception occurred retrieving tunnel information", e);
}
return null;
}
Expand Down Expand Up @@ -693,7 +692,7 @@ protected void processLine(String line) {
if (printStream != null) {
printStream.println(line);
}
julLogger.info(line);
LOGGER.info(line);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;

import java.net.URL;

Expand Down Expand Up @@ -204,12 +203,7 @@ protected Process prepAndCreateProcess(
args = generateSauceConnectArgs(args, username, apiKey, port, options);
args = addExtraInfo(args);

julLogger.log(
Level.INFO,
"Launching Sauce Connect "
+ getCurrentVersion()
+ " "
+ hideSauceConnectCommandlineSecrets(args));
LOGGER.info("Launching Sauce Connect {} {}", getCurrentVersion(), hideSauceConnectCommandlineSecrets(args));
return createProcess(args, sauceConnectBinary.getParentFile());
} catch (IOException e) {
throw new SauceConnectException(e);
Expand Down

0 comments on commit 6c6f527

Please sign in to comment.