Skip to content

Commit 90de1ff

Browse files
authored
HADOOP-18206 Cleanup the commons-logging references and restrict its usage in future (apache#5315)
1 parent 30f5605 commit 90de1ff

File tree

71 files changed

+223
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+223
-532
lines changed

LICENSE-binary

-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ commons-codec:commons-codec:1.11
250250
commons-collections:commons-collections:3.2.2
251251
commons-daemon:commons-daemon:1.0.13
252252
commons-io:commons-io:2.8.0
253-
commons-logging:commons-logging:1.1.3
254253
commons-net:commons-net:3.9.0
255254
de.ruedigermoeller:fst:2.50
256255
io.grpc:grpc-api:1.26.0

hadoop-common-project/hadoop-common/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@
180180
<artifactId>jersey-server</artifactId>
181181
<scope>compile</scope>
182182
</dependency>
183-
<dependency>
184-
<groupId>commons-logging</groupId>
185-
<artifactId>commons-logging</artifactId>
186-
<scope>compile</scope>
187-
</dependency>
188183
<dependency>
189184
<groupId>log4j</groupId>
190185
<artifactId>log4j</artifactId>

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java

-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434

35-
import org.apache.commons.logging.Log;
3635
import org.apache.hadoop.classification.InterfaceAudience;
3736
import org.apache.hadoop.classification.InterfaceStability;
3837
import org.apache.hadoop.conf.Configuration;
@@ -246,30 +245,6 @@ public static void skipFully(InputStream in, long len) throws IOException {
246245
}
247246
}
248247

249-
/**
250-
* Close the Closeable objects and <b>ignore</b> any {@link Throwable} or
251-
* null pointers. Must only be used for cleanup in exception handlers.
252-
*
253-
* @param log the log to record problems to at debug level. Can be null.
254-
* @param closeables the objects to close
255-
* @deprecated use {@link #cleanupWithLogger(Logger, java.io.Closeable...)}
256-
* instead
257-
*/
258-
@Deprecated
259-
public static void cleanup(Log log, java.io.Closeable... closeables) {
260-
for (java.io.Closeable c : closeables) {
261-
if (c != null) {
262-
try {
263-
c.close();
264-
} catch(Throwable e) {
265-
if (log != null && log.isDebugEnabled()) {
266-
log.debug("Exception in closing " + c, e);
267-
}
268-
}
269-
}
270-
}
271-
}
272-
273248
/**
274249
* Close the Closeable objects and <b>ignore</b> any {@link Throwable} or
275250
* null pointers. Must only be used for cleanup in exception handlers.

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java

+7-33
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434

3535
import org.apache.hadoop.classification.VisibleForTesting;
3636
import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
37-
import org.apache.commons.logging.Log;
38-
import org.apache.commons.logging.LogFactory;
39-
import org.apache.commons.logging.impl.Jdk14Logger;
40-
import org.apache.commons.logging.impl.Log4JLogger;
4137
import org.apache.hadoop.HadoopIllegalArgumentException;
4238
import org.apache.hadoop.classification.InterfaceAudience;
4339
import org.apache.hadoop.classification.InterfaceStability;
@@ -51,6 +47,8 @@
5147
import org.apache.hadoop.util.ServletUtil;
5248
import org.apache.hadoop.util.Tool;
5349
import org.apache.hadoop.util.ToolRunner;
50+
import org.apache.log4j.Level;
51+
import org.apache.log4j.Logger;
5452

5553
/**
5654
* Change log level in runtime.
@@ -340,22 +338,14 @@ public void doGet(HttpServletRequest request, HttpServletResponse response
340338
out.println(MARKER
341339
+ "Submitted Class Name: <b>" + logName + "</b><br />");
342340

343-
Log log = LogFactory.getLog(logName);
341+
Logger log = Logger.getLogger(logName);
344342
out.println(MARKER
345343
+ "Log Class: <b>" + log.getClass().getName() +"</b><br />");
346344
if (level != null) {
347345
out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
348346
}
349347

350-
if (log instanceof Log4JLogger) {
351-
process(((Log4JLogger)log).getLogger(), level, out);
352-
}
353-
else if (log instanceof Jdk14Logger) {
354-
process(((Jdk14Logger)log).getLogger(), level, out);
355-
}
356-
else {
357-
out.println("Sorry, " + log.getClass() + " not supported.<br />");
358-
}
348+
process(log, level, out);
359349
}
360350

361351
out.println(FORMS);
@@ -371,36 +361,20 @@ else if (log instanceof Jdk14Logger) {
371361
+ "<input type='submit' value='Set Log Level' />"
372362
+ "</form>";
373363

374-
private static void process(org.apache.log4j.Logger log, String level,
364+
private static void process(Logger log, String level,
375365
PrintWriter out) throws IOException {
376366
if (level != null) {
377-
if (!level.equalsIgnoreCase(org.apache.log4j.Level.toLevel(level)
367+
if (!level.equalsIgnoreCase(Level.toLevel(level)
378368
.toString())) {
379369
out.println(MARKER + "Bad Level : <b>" + level + "</b><br />");
380370
} else {
381-
log.setLevel(org.apache.log4j.Level.toLevel(level));
371+
log.setLevel(Level.toLevel(level));
382372
out.println(MARKER + "Setting Level to " + level + " ...<br />");
383373
}
384374
}
385375
out.println(MARKER
386376
+ "Effective Level: <b>" + log.getEffectiveLevel() + "</b><br />");
387377
}
388378

389-
private static void process(java.util.logging.Logger log, String level,
390-
PrintWriter out) throws IOException {
391-
if (level != null) {
392-
String levelToUpperCase = level.toUpperCase();
393-
try {
394-
log.setLevel(java.util.logging.Level.parse(levelToUpperCase));
395-
} catch (IllegalArgumentException e) {
396-
out.println(MARKER + "Bad Level : <b>" + level + "</b><br />");
397-
}
398-
out.println(MARKER + "Setting Level to " + level + " ...<br />");
399-
}
400-
401-
java.util.logging.Level lev;
402-
for(; (lev = log.getLevel()) == null; log = log.getParent());
403-
out.println(MARKER + "Effective Level: <b>" + lev + "</b><br />");
404-
}
405379
}
406380
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/ServiceOperations.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323

24-
import org.apache.commons.logging.Log;
2524
import org.apache.hadoop.classification.InterfaceAudience.Public;
2625
import org.apache.hadoop.classification.InterfaceStability.Evolving;
2726
import org.slf4j.Logger;
@@ -75,9 +74,10 @@ public static Exception stopQuietly(Service service) {
7574
* @param log the log to warn at
7675
* @param service a service; may be null
7776
* @return any exception that was caught; null if none was.
78-
* @see ServiceOperations#stopQuietly(Service)
77+
* @deprecated to be removed with 3.4.0. Use {@link #stopQuietly(Logger, Service)} instead.
7978
*/
80-
public static Exception stopQuietly(Log log, Service service) {
79+
@Deprecated
80+
public static Exception stopQuietly(org.apache.commons.logging.Log log, Service service) {
8181
try {
8282
stop(service);
8383
} catch (Exception e) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LogAdapter.java

-78
This file was deleted.

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ReflectionUtils.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.Map;
3737
import java.util.concurrent.ConcurrentHashMap;
3838

39-
import org.apache.commons.logging.Log;
4039
import org.apache.hadoop.classification.InterfaceAudience;
4140
import org.apache.hadoop.classification.InterfaceStability;
4241
import org.apache.hadoop.conf.Configurable;
@@ -222,16 +221,18 @@ public synchronized static void printThreadInfo(PrintStream stream,
222221
}
223222

224223
private static long previousLogTime = 0;
225-
224+
226225
/**
227226
* Log the current thread stacks at INFO level.
228227
* @param log the logger that logs the stack trace
229228
* @param title a descriptive title for the call stacks
230-
* @param minInterval the minimum time from the last
229+
* @param minInterval the minimum time from the last
230+
* @deprecated to be removed with 3.4.0. Use {@link #logThreadInfo(Logger, String, long)} instead.
231231
*/
232-
public static void logThreadInfo(Log log,
233-
String title,
234-
long minInterval) {
232+
@Deprecated
233+
public static void logThreadInfo(org.apache.commons.logging.Log log,
234+
String title,
235+
long minInterval) {
235236
boolean dumpStack = false;
236237
if (log.isInfoEnabled()) {
237238
synchronized (ReflectionUtils.class) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SignalLogger.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
package org.apache.hadoop.util;
2020

21+
import org.slf4j.Logger;
2122
import sun.misc.Signal;
2223
import sun.misc.SignalHandler;
2324

24-
import org.apache.commons.logging.Log;
2525
import org.apache.hadoop.classification.InterfaceAudience;
2626
import org.apache.hadoop.classification.InterfaceStability;
2727

@@ -42,11 +42,11 @@ public enum SignalLogger {
4242
* Our signal handler.
4343
*/
4444
private static class Handler implements SignalHandler {
45-
final private LogAdapter LOG;
45+
final private Logger log;
4646
final private SignalHandler prevHandler;
4747

48-
Handler(String name, LogAdapter LOG) {
49-
this.LOG = LOG;
48+
Handler(String name, Logger log) {
49+
this.log = log;
5050
prevHandler = Signal.handle(new Signal(name), this);
5151
}
5252

@@ -57,7 +57,7 @@ private static class Handler implements SignalHandler {
5757
*/
5858
@Override
5959
public void handle(Signal signal) {
60-
LOG.error("RECEIVED SIGNAL " + signal.getNumber() +
60+
log.error("RECEIVED SIGNAL " + signal.getNumber() +
6161
": SIG" + signal.getName());
6262
prevHandler.handle(signal);
6363
}
@@ -66,13 +66,9 @@ public void handle(Signal signal) {
6666
/**
6767
* Register some signal handlers.
6868
*
69-
* @param LOG The log4j logfile to use in the signal handlers.
69+
* @param log The log4j logfile to use in the signal handlers.
7070
*/
71-
public void register(final Log LOG) {
72-
register(LogAdapter.create(LOG));
73-
}
74-
75-
void register(final LogAdapter LOG) {
71+
public void register(final Logger log) {
7672
if (registered) {
7773
throw new IllegalStateException("Can't re-install the signal handlers.");
7874
}
@@ -83,15 +79,15 @@ void register(final LogAdapter LOG) {
8379
String separator = "";
8480
for (String signalName : SIGNALS) {
8581
try {
86-
new Handler(signalName, LOG);
82+
new Handler(signalName, log);
8783
bld.append(separator)
8884
.append(signalName);
8985
separator = ", ";
9086
} catch (Exception e) {
91-
LOG.debug(e);
87+
log.debug("Error: ", e);
9288
}
9389
}
9490
bld.append("]");
95-
LOG.info(bld.toString());
91+
log.info(bld.toString());
9692
}
9793
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java

+6-22
Original file line numberDiff line numberDiff line change
@@ -740,42 +740,26 @@ public static String toStartupShutdownString(String prefix, String[] msg) {
740740
* Print a log message for starting up and shutting down
741741
* @param clazz the class of the server
742742
* @param args arguments
743-
* @param LOG the target log object
743+
* @param log the target log object
744744
*/
745745
public static void startupShutdownMessage(Class<?> clazz, String[] args,
746-
final org.apache.commons.logging.Log LOG) {
747-
startupShutdownMessage(clazz, args, LogAdapter.create(LOG));
748-
}
749-
750-
/**
751-
* Print a log message for starting up and shutting down
752-
* @param clazz the class of the server
753-
* @param args arguments
754-
* @param LOG the target log object
755-
*/
756-
public static void startupShutdownMessage(Class<?> clazz, String[] args,
757-
final org.slf4j.Logger LOG) {
758-
startupShutdownMessage(clazz, args, LogAdapter.create(LOG));
759-
}
760-
761-
static void startupShutdownMessage(Class<?> clazz, String[] args,
762-
final LogAdapter LOG) {
746+
final org.slf4j.Logger log) {
763747
final String hostname = NetUtils.getHostname();
764748
final String classname = clazz.getSimpleName();
765-
LOG.info(createStartupShutdownMessage(classname, hostname, args));
749+
log.info(createStartupShutdownMessage(classname, hostname, args));
766750

767751
if (SystemUtils.IS_OS_UNIX) {
768752
try {
769-
SignalLogger.INSTANCE.register(LOG);
753+
SignalLogger.INSTANCE.register(log);
770754
} catch (Throwable t) {
771-
LOG.warn("failed to register any UNIX signal loggers: ", t);
755+
log.warn("failed to register any UNIX signal loggers: ", t);
772756
}
773757
}
774758
ShutdownHookManager.get().addShutdownHook(
775759
new Runnable() {
776760
@Override
777761
public void run() {
778-
LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
762+
log.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
779763
"Shutting down " + classname + " at " + hostname}));
780764
LogManager.shutdown();
781765
}

0 commit comments

Comments
 (0)