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

Use slf4j+java.util.logging for logging needs. #383

Merged
merged 31 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b1a28f3
App: remove all usage of Log4J and use the java.util.logging system i…
remeh Dec 16, 2021
0b500ed
CustomLogger: proper init of stdout, stderr and/or file handlers.
remeh Dec 17, 2021
505ee70
CustomLogger: simpleClassName removes subclasses.
remeh Dec 17, 2021
30b4041
LogLevel: more lenient log level parsing and support `FATAL` for comp…
remeh Dec 17, 2021
896528a
[logger] fixing timezone issues
truthbk Dec 18, 2021
31fc4b5
[logger] test: adding performance test
truthbk Dec 20, 2021
13311f5
[gitignore] updating for jenv hidden file
truthbk Dec 20, 2021
d6ddc7e
[logging] adding comments/opinions
truthbk Dec 20, 2021
e012a0d
CustomLogger: add `shutdown()` method to close handlers.
remeh Dec 20, 2021
6d94171
Linter compliance.
remeh Dec 20, 2021
8cd180d
Address feedback.
remeh Dec 20, 2021
dbab8a6
Update src/main/java/org/datadog/jmxfetch/util/LogLevel.java
remeh Dec 20, 2021
c707470
Address feedback.
remeh Dec 20, 2021
eba1678
Set log level on root logger
olivielpeau Dec 20, 2021
13883ef
Fix mapping of JMXFetch to JUL log level for debug and trace
olivielpeau Dec 20, 2021
ba82396
[CustomLogger] Fix file rotation handling
sgnn7 Dec 20, 2021
5da3101
[logging] test: adding throttling.
truthbk Dec 20, 2021
b28c4f9
Merge branch 'remeh/jdk14' of github.com:DataDog/jmxfetch into remeh/…
truthbk Dec 20, 2021
7b1ee97
[logger] fix filters; only log org.datadog.jmxfetch.*
truthbk Dec 21, 2021
17ec3ab
[lint] addressing some lint issues
truthbk Dec 21, 2021
d7121c3
[logger] removing the old RFC3339 layout
truthbk Dec 21, 2021
5d56009
[logger] hold static reference to root logger.
truthbk Dec 21, 2021
7484147
Simplify setup logic, use our own logger instead of the root one
olivielpeau Dec 21, 2021
188260d
Re-introduce shutdown
olivielpeau Dec 21, 2021
41d4660
LogLevel: reverse assigned numbers (and the test condition) for clari…
remeh Dec 21, 2021
2f04428
CustomLogger: fix `laconic` level test for error/all.
remeh Dec 21, 2021
96bd205
LogLevel: fix levels order in comment + removed unused `contains()` m…
remeh Dec 21, 2021
df4ce60
Add note about "LEVEL" log level + add tests
olivielpeau Dec 21, 2021
c33a8d6
Update src/main/java/org/datadog/jmxfetch/util/CustomLogger.java
remeh Dec 21, 2021
4d3df0e
CustomLogger: display exceptions stack trace if any throwable has bee…
remeh Dec 21, 2021
8e80e5a
CustomLogger: use approriate method to add a line return instead of w…
remeh Dec 21, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ target/*

# jenv
.java_version
.java-version
remeh marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 5 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
<apache-commons-lang3.version>3.5</apache-commons-lang3.version>
<java-dogstatsd-client.version>2.10.5</java-dogstatsd-client.version>
<jcommander.version>1.35</jcommander.version>
<!-- log4j 2.13+ drops support for Java 7, so stick to 2.12 -->
<log4j.version>2.12.2</log4j.version>
<slf4j.version>1.7.26</slf4j.version>
<slf4j.version>1.7.32</slf4j.version>
<jackson.version>2.12.3</jackson.version>
<snakeyaml.version>1.26</snakeyaml.version>
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
Expand Down Expand Up @@ -167,28 +165,10 @@
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<!-- use same version as the API -->
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;

import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.tasks.TaskMethod;
Expand All @@ -17,6 +15,7 @@
import org.datadog.jmxfetch.util.ByteArraySearcher;
import org.datadog.jmxfetch.util.CustomLogger;
import org.datadog.jmxfetch.util.FileHelper;
import org.datadog.jmxfetch.util.LogLevel;
import org.datadog.jmxfetch.util.MetadataHelper;
import org.datadog.jmxfetch.util.ServiceCheckHelper;
import org.slf4j.Marker;
Expand Down Expand Up @@ -144,7 +143,7 @@ public static void main(String[] args) {
// not needed in dd-java-agent, which calls run directly.

// Set up the logger to add file handler
CustomLogger.setup(Level.toLevel(config.getLogLevel()),
CustomLogger.setup(LogLevel.fromString(config.getLogLevel()),
config.getLogLocation(),
config.isLogFormatRfc3339());

Expand All @@ -161,21 +160,18 @@ public static void main(String[] args) {
* System#exit}.
*/
public int run() {
Marker fatal = MarkerFactory.getMarker("FATAL");
String action = appConfig.getAction();

// The specified action is unknown
if (!AppConfig.ACTIONS.contains(action)) {
log.error(fatal,
action + " is not in " + AppConfig.ACTIONS + ". Exiting.");
log.error(action + " is not in " + AppConfig.ACTIONS + ". Exiting.");
return 1;
}

if (!action.equals(AppConfig.ACTION_COLLECT)
&& !(appConfig.isConsoleReporter() || appConfig.isJsonReporter())) {
// The "list_*" actions can not be used with the statsd reporter
log.error(fatal,
action
log.error(action
+ " argument can only be used with the console or json reporter. Exiting.");
return 1;
}
Expand Down Expand Up @@ -230,8 +226,7 @@ private static void attachShutdownHook() {
@Override
public void run() {
log.info("JMXFetch is closing");
// Properly close log handlers
LogManager.shutdown();
// make sure log handlers are properly closed
olivielpeau marked this conversation as resolved.
Show resolved Hide resolved
}
}
);
Expand Down Expand Up @@ -1192,7 +1187,7 @@ private <T> void processCollectionStatus(
+ " metrics.";

instanceStatus = Status.STATUS_WARNING;
CustomLogger.laconic(log, Level.WARN, instanceMessage, 0);
CustomLogger.laconic(log, LogLevel.WARN, instanceMessage, 0);
}

if (numberOfMetrics > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.datadog.jmxfetch.reporter.JsonReporter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.service.ServiceNameProvider;
import org.datadog.jmxfetch.validator.Log4JLevelValidator;
import org.datadog.jmxfetch.validator.LogLevelValidator;
import org.datadog.jmxfetch.validator.PositiveIntegerValidator;
import org.datadog.jmxfetch.validator.ReporterValidator;

Expand Down Expand Up @@ -73,7 +73,7 @@ public class AppConfig {
@Parameter(
names = {"--log_level", "-L"},
description = "Level of verbosity",
validateWith = Log4JLevelValidator.class,
validateWith = LogLevelValidator.class,
required = false)
@Builder.Default
private String logLevel = "INFO";
Expand Down
Loading