Skip to content

Commit 5801811

Browse files
committed
Use SLF4J as logger
1 parent 345e8ac commit 5801811

74 files changed

Lines changed: 492 additions & 466 deletions

File tree

Some content is hidden

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

proxy/pom.xml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,6 @@
291291
<artifactId>gson</artifactId>
292292
<version>2.9.0</version>
293293
</dependency>
294-
<dependency>
295-
<groupId>org.slf4j</groupId>
296-
<artifactId>slf4j-api</artifactId>
297-
<version>2.0.3</version>
298-
</dependency>
299294
<dependency>
300295
<groupId>io.netty</groupId>
301296
<artifactId>netty-bom</artifactId>
@@ -377,7 +372,7 @@
377372
<dependency>
378373
<groupId>org.apache.logging.log4j</groupId>
379374
<artifactId>log4j-bom</artifactId>
380-
<version>2.17.2</version>
375+
<version>2.19.0</version>
381376
<type>pom</type>
382377
<scope>import</scope>
383378
</dependency>
@@ -402,12 +397,14 @@
402397
</dependencyManagement>
403398

404399
<dependencies>
405-
<dependency>
406-
<groupId>org.slf4j</groupId>
407-
<artifactId>slf4j-nop</artifactId>
408-
<version>2.0.3</version>
409-
</dependency>
410-
<!-- https://mvnrepository.com/artifact/org.apache.activemq/artemis-server -->
400+
<dependency>
401+
<groupId>org.apache.logging.log4j</groupId>
402+
<artifactId>log4j-core</artifactId>
403+
</dependency>
404+
<dependency>
405+
<groupId>org.apache.logging.log4j</groupId>
406+
<artifactId>log4j-slf4j2-impl</artifactId>
407+
</dependency>
411408
<dependency>
412409
<groupId>org.apache.activemq</groupId>
413410
<artifactId>artemis-server</artifactId>
@@ -607,11 +604,6 @@
607604
<artifactId>chronicle-map</artifactId>
608605
<version>3.21.86</version>
609606
</dependency>
610-
<dependency>
611-
<groupId>org.springframework.boot</groupId>
612-
<artifactId>spring-boot-starter-log4j2</artifactId>
613-
<version>2.7.0</version>
614-
</dependency>
615607
<dependency>
616608
<groupId>io.grpc</groupId>
617609
<artifactId>grpc-stub</artifactId>

proxy/src/main/java/com/wavefront/agent/AbstractAgent.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@
3333
import java.util.concurrent.ExecutorService;
3434
import java.util.concurrent.TimeUnit;
3535
import java.util.concurrent.atomic.AtomicBoolean;
36-
import java.util.logging.Level;
37-
import java.util.logging.Logger;
3836
import java.util.stream.Collectors;
3937
import java.util.stream.IntStream;
4038
import javax.net.ssl.SSLException;
4139
import org.apache.commons.lang.StringUtils;
4240
import org.apache.commons.lang3.ObjectUtils;
41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
4343

4444
/** Agent that runs remotely on a server collecting metrics. */
4545
public abstract class AbstractAgent {
46-
private static final Logger logger = Logger.getLogger(AbstractAgent.class.getCanonicalName());
46+
private static final Logger logger =
47+
LoggerFactory.getLogger(AbstractAgent.class.getCanonicalName());
4748
/** A set of commandline parameters to hide when echoing command line arguments */
4849
protected static final Set<String> PARAMETERS_TO_HIDE =
4950
ImmutableSet.of("-t", "--token", "--proxyPassword");
@@ -131,9 +132,9 @@ protected LogsIngestionConfig loadLogsIngestionConfig() {
131132
return objectMapper.readValue(
132133
new File(proxyConfig.getLogsIngestionConfigFile()), LogsIngestionConfig.class);
133134
} catch (UnrecognizedPropertyException e) {
134-
logger.severe("Unable to load logs ingestion config: " + e.getMessage());
135+
logger.error("Unable to load logs ingestion config: " + e.getMessage());
135136
} catch (Exception e) {
136-
logger.log(Level.SEVERE, "Could not load logs ingestion config", e);
137+
logger.error("Could not load logs ingestion config", e);
137138
}
138139
return null;
139140
}
@@ -143,9 +144,9 @@ private void postProcessConfig() {
143144
// connection. the alternative is to always validate connections before reuse, but since
144145
// it happens fairly infrequently, and connection re-validation performance penalty is
145146
// incurred every time, suppressing that message seems to be a more reasonable approach.
146-
// org.apache.log4j.Logger.getLogger("org.apache.http.impl.execchain.RetryExec").
147+
// org.apache.log4j.LoggerFactory.getLogger("org.apache.http.impl.execchain.RetryExec").
147148
// setLevel(org.apache.log4j.Level.WARN);
148-
// Logger.getLogger("org.apache.http.impl.execchain.RetryExec").setLevel(Level.WARNING);
149+
// LoggerFactory.getLogger("org.apache.http.impl.execchain.RetryExec").setLevel(Level.WARNING);
149150

150151
if (StringUtils.isBlank(proxyConfig.getHostname().trim())) {
151152
throw new IllegalArgumentException(
@@ -170,7 +171,7 @@ void parseArguments(String[] args) {
170171
}
171172
} catch (ParameterException e) {
172173
logger.info(versionStr);
173-
logger.severe("Parameter exception: " + e.getMessage());
174+
logger.error("Parameter exception: " + e.getMessage());
174175
System.exit(1);
175176
}
176177
logger.info(versionStr);
@@ -271,11 +272,11 @@ public void start(String[] args) {
271272
public void run() {
272273
// exit if no active listeners
273274
if (activeListeners.count() == 0) {
274-
logger.severe(
275+
logger.error(
275276
"**** All listener threads failed to start - there is already a "
276277
+ "running instance listening on configured ports, or no listening ports "
277278
+ "configured!");
278-
logger.severe("Aborting start-up");
279+
logger.error("Aborting start-up");
279280
System.exit(1);
280281
}
281282

@@ -293,8 +294,8 @@ public void run() {
293294
},
294295
5000);
295296
} catch (Exception e) {
296-
logger.log(Level.SEVERE, e.getMessage(), e);
297-
// logger.severe(e.getMessage());
297+
logger.error(e.getMessage(), e);
298+
// logger.error(e.getMessage());
298299
System.exit(1);
299300
}
300301
}
@@ -351,7 +352,7 @@ public void shutdown() {
351352
System.out.println("Shutdown complete.");
352353
} catch (Throwable t) {
353354
try {
354-
logger.log(Level.SEVERE, "Error during shutdown: ", t);
355+
logger.error("Error during shutdown: ", t);
355356
} catch (Throwable loggingError) {
356357
t.addSuppressed(loggingError);
357358
t.printStackTrace();

proxy/src/main/java/com/wavefront/agent/ProxyCheckInScheduler.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
import java.util.concurrent.atomic.AtomicInteger;
2727
import java.util.concurrent.atomic.AtomicLong;
2828
import java.util.function.BiConsumer;
29-
import java.util.logging.Level;
30-
import java.util.logging.Logger;
3129
import javax.ws.rs.ClientErrorException;
3230
import javax.ws.rs.ProcessingException;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3333

3434
/**
3535
* Registers the proxy with the back-end, sets up regular "check-ins" (every minute), transmits
3636
* proxy metrics to the back-end.
3737
*/
3838
public class ProxyCheckInScheduler {
3939
private static final Logger logger =
40-
Logger.getLogger(ProxyCheckInScheduler.class.getCanonicalName());
40+
LoggerFactory.getLogger(ProxyCheckInScheduler.class.getCanonicalName());
4141
private static final int MAX_CHECKIN_ATTEMPTS = 5;
4242

4343
/**
@@ -315,18 +315,18 @@ void updateConfiguration() {
315315
continue;
316316
}
317317
if (configEntry.getKey().equals(APIContainer.CENTRAL_TENANT_NAME)) {
318-
if (logger.isLoggable(Level.FINE)) {
319-
logger.fine("Server configuration getShutOffAgents: " + config.getShutOffAgents());
320-
logger.fine("Server configuration isTruncateQueue: " + config.isTruncateQueue());
318+
if (logger.isDebugEnabled()) {
319+
logger.info("Server configuration getShutOffAgents: " + config.getShutOffAgents());
320+
logger.info("Server configuration isTruncateQueue: " + config.isTruncateQueue());
321321
}
322322
if (config.getShutOffAgents()) {
323-
logger.warning(
323+
logger.warn(
324324
firstNonNull(
325325
config.getShutOffMessage(),
326326
"Shutting down: Server side flag indicating proxy has to shut down."));
327327
shutdownHook.run();
328328
} else if (config.isTruncateQueue()) {
329-
logger.warning(
329+
logger.warn(
330330
"Truncating queue: Server side flag indicating proxy queue has to be truncated.");
331331
truncateBacklog.run();
332332
}
@@ -335,7 +335,7 @@ void updateConfiguration() {
335335
}
336336
}
337337
} catch (Exception e) {
338-
logger.log(Level.SEVERE, "Exception occurred during configuration update", e);
338+
logger.error("Exception occurred during configuration update", e);
339339
}
340340
}
341341

@@ -353,13 +353,13 @@ void updateProxyMetrics() {
353353
retries.set(0);
354354
}
355355
} catch (Exception ex) {
356-
logger.log(Level.SEVERE, "Could not generate proxy metrics", ex);
356+
logger.error("Could not generate proxy metrics", ex);
357357
}
358358
}
359359

360360
private void checkinError(String errMsg) {
361-
if (successfulCheckIns.get() == 0) logger.severe(Strings.repeat("*", errMsg.length()));
362-
logger.severe(errMsg);
363-
if (successfulCheckIns.get() == 0) logger.severe(Strings.repeat("*", errMsg.length()));
361+
if (successfulCheckIns.get() == 0) logger.error(Strings.repeat("*", errMsg.length()));
362+
logger.error(errMsg);
363+
if (successfulCheckIns.get() == 0) logger.error(Strings.repeat("*", errMsg.length()));
364364
}
365365
}

proxy/src/main/java/com/wavefront/agent/ProxyConfig.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
import com.wavefront.agent.config.ReportableConfig;
2222
import com.wavefront.common.TimeProvider;
2323
import java.util.*;
24-
import java.util.logging.Logger;
2524
import org.apache.commons.lang3.ObjectUtils;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2627

2728
/** Proxy configuration (refactored from {@link AbstractAgent}). */
2829
@SuppressWarnings("CanBeFinal")
2930
public class ProxyConfig extends Configuration {
30-
private static final Logger logger = Logger.getLogger(ProxyConfig.class.getCanonicalName());
31+
private static final Logger logger =
32+
LoggerFactory.getLogger(ProxyConfig.class.getCanonicalName());
3133
private static final double MAX_RETRY_BACKOFF_BASE_SECONDS = 60.0;
3234
private static final int GRAPHITE_LISTENING_PORT = 2878;
3335

@@ -1723,8 +1725,7 @@ public List<String> getCustomSourceTags() {
17231725
.forEach(
17241726
x -> {
17251727
if (!tagSet.add(x)) {
1726-
logger.warning(
1727-
"Duplicate tag " + x + " specified in customSourceTags config setting");
1728+
logger.warn("Duplicate tag " + x + " specified in customSourceTags config setting");
17281729
}
17291730
});
17301731
return new ArrayList<>(tagSet);
@@ -1740,7 +1741,7 @@ public List<String> getCustomTimestampTags() {
17401741
.forEach(
17411742
x -> {
17421743
if (!tagSet.add(x)) {
1743-
logger.warning(
1744+
logger.warn(
17441745
"Duplicate tag " + x + " specified in customTimestampTags config setting");
17451746
}
17461747
});
@@ -1757,7 +1758,7 @@ public List<String> getCustomMessageTags() {
17571758
.forEach(
17581759
x -> {
17591760
if (!tagSet.add(x)) {
1760-
logger.warning(
1761+
logger.warn(
17611762
"Duplicate tag " + x + " specified in customMessageTags config setting");
17621763
}
17631764
});
@@ -1774,7 +1775,7 @@ public List<String> getCustomApplicationTags() {
17741775
.forEach(
17751776
x -> {
17761777
if (!tagSet.add(x)) {
1777-
logger.warning(
1778+
logger.warn(
17781779
"Duplicate tag " + x + " specified in customApplicationTags config setting");
17791780
}
17801781
});
@@ -1791,7 +1792,7 @@ public List<String> getCustomServiceTags() {
17911792
.forEach(
17921793
x -> {
17931794
if (!tagSet.add(x)) {
1794-
logger.warning(
1795+
logger.warn(
17951796
"Duplicate tag " + x + " specified in customServiceTags config setting");
17961797
}
17971798
});
@@ -1807,7 +1808,7 @@ public List<String> getCustomExceptionTags() {
18071808
.forEach(
18081809
x -> {
18091810
if (!tagSet.add(x)) {
1810-
logger.warning(
1811+
logger.warn(
18111812
"Duplicate tag " + x + " specified in customExceptionTags config setting");
18121813
}
18131814
});
@@ -1824,8 +1825,7 @@ public List<String> getCustomLevelTags() {
18241825
.forEach(
18251826
x -> {
18261827
if (!tagSet.add(x)) {
1827-
logger.warning(
1828-
"Duplicate tag " + x + " specified in customLevelTags config setting");
1828+
logger.warn("Duplicate tag " + x + " specified in customLevelTags config setting");
18291829
}
18301830
});
18311831
return new ArrayList<>(tagSet);
@@ -2039,7 +2039,7 @@ public void verifyAndInit() {
20392039
hostname = config.getString("hostname", hostname);
20402040
proxyname = config.getString("proxyname", proxyname);
20412041
if (!hostname.equals(FQDN)) {
2042-
logger.warning(
2042+
logger.warn(
20432043
"Deprecated field hostname specified in config setting. Please use "
20442044
+ "proxyname config field to set proxy name.");
20452045
if (proxyname.equals(FQDN)) proxyname = hostname;
@@ -2472,7 +2472,7 @@ public void verifyAndInit() {
24722472
config.getInteger("memoryBufferExpirationTime", memoryBufferExpirationTime);
24732473
disableBuffer = config.getBoolean("disable_buffer", disableBuffer);
24742474
} catch (Throwable exception) {
2475-
logger.severe("Could not load configuration file " + pushConfigFile);
2475+
logger.error("Could not load configuration file " + pushConfigFile);
24762476
throw new RuntimeException(exception.getMessage());
24772477
}
24782478
if (httpUserAgent == null) {

proxy/src/main/java/com/wavefront/agent/ProxyUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import java.util.Objects;
2121
import java.util.UUID;
2222
import java.util.function.Supplier;
23-
import java.util.logging.Logger;
2423
import javax.annotation.Nullable;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
2526

2627
/** Miscellaneous support methods for running Wavefront proxy. */
2728
public abstract class ProxyUtil {
28-
protected static final Logger logger = Logger.getLogger(ProxyUtil.class.getCanonicalName());
29+
protected static final Logger logger =
30+
LoggerFactory.getLogger(ProxyUtil.class.getCanonicalName());
2931

3032
private ProxyUtil() {}
3133

0 commit comments

Comments
 (0)