Skip to content

Commit cbae949

Browse files
committed
Add JUL implementation
1 parent 93676a2 commit cbae949

File tree

7 files changed

+53
-15
lines changed

7 files changed

+53
-15
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ Debug sysErrDebug = new PrintStreamDebug(System.err);
5656
provider.setDebug(sysErrDebug);
5757
```
5858

59+
or use java.util.logging:
60+
61+
```java
62+
provider.setDebug(new LoggingDebug(DEBUG, debugLogger));
63+
```
64+
5965
And you can add your own logging framework by extending `AbstractDebug`:
6066

6167
```java

lib/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
`java-library`
1111
`maven-publish` // https://docs.gradle.org/current/userguide/publishing_maven.html
1212
signing
13+
id("com.diffplug.spotless") version "7.0.0.BETA4"
1314
}
1415

1516
repositories {

lib/src/main/java/com/tersesystems/debugjsse/AbstractDebug.java

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import java.util.*;
1010
import java.util.concurrent.atomic.AtomicInteger;
1111

12+
/**
13+
* This is an abstract class that provides helpful defaults for most of the Debug interface.
14+
*
15+
* There's three methods you have to implement, but the key/trust manager is taken care of for you.
16+
*/
1217
public abstract class AbstractDebug implements Debug {
1318

1419
public abstract void enter(String message);

lib/src/main/java/com/tersesystems/debugjsse/DebugJSSEProvider.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
package com.tersesystems.debugjsse;
22

3-
import javax.net.ssl.KeyManagerFactory;
4-
import javax.net.ssl.SSLContext;
5-
import javax.net.ssl.SSLContextSpi;
6-
import javax.net.ssl.TrustManagerFactory;
7-
83
import java.security.NoSuchAlgorithmException;
94
import java.security.NoSuchProviderException;
105
import java.security.Provider;
116
import java.security.Security;
127
import java.util.Arrays;
138
import java.util.Collections;
14-
import java.util.Set;
159

1610
public class DebugJSSEProvider extends Provider {
1711

18-
private static String defaultKeyManagerAlgorithm;
19-
private static String defaultTrustManagerAlgorithm;
20-
2112
public final static String NAME = "debugJSSE";
2213
public final static Double VERSION = 1.0;
2314
public final static String INFO = "Debug JSSE";
2415

25-
private static final String SSL_KEY_MANAGER_FACTORY_SECPROP = "ssl.KeyManagerFactory.algorithm";
26-
private static final String SSL_TRUST_MANAGER_FACTORY_SECPROP = "ssl.TrustManagerFactory.algorithm";
27-
private static final String KEY_MANAGER_FACTORY = "KeyManagerFactory";
28-
private static final String TRUST_MANAGER_FACTORY = "TrustManagerFactory";
16+
private static final String KEY_MANAGER_FACTORY = "KeyManagerFactory";
17+
private static final String TRUST_MANAGER_FACTORY = "TrustManagerFactory";
2918

3019
private static boolean enabled = false;
3120

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.tersesystems.debugjsse;
2+
3+
import java.util.logging.Level;
4+
import java.util.logging.Logger;
5+
6+
/**
7+
* This is a class that logs to the given logger at the given log level.
8+
*/
9+
public class LoggingDebug extends AbstractDebug {
10+
11+
private final Logger logger;
12+
private final Level level;
13+
14+
public LoggingDebug(Level level, Logger logger) {
15+
this.level = level;
16+
this.logger = logger;
17+
}
18+
19+
@Override
20+
public void enter(String message) {
21+
logger.log(level, message);
22+
}
23+
24+
@Override
25+
public void exit(String message) {
26+
logger.log(level, message);
27+
}
28+
29+
@Override
30+
public void exception(String message, Exception e) {
31+
logger.log(level, message);
32+
}
33+
}

lib/src/main/java/com/tersesystems/debugjsse/PrintStreamDebug.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.tersesystems.debugjsse;
22

3-
import javax.net.ssl.KeyManagerFactory;
4-
import javax.net.ssl.TrustManagerFactory;
53
import java.io.PrintStream;
64

5+
/**
6+
* This is a class that prints to a PrintStream on debug output.
7+
*/
78
public class PrintStreamDebug extends AbstractDebug {
89

910
private final PrintStream stream;

lib/src/main/java/com/tersesystems/debugjsse/SystemOutDebug.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.tersesystems.debugjsse;
22

3+
/**
4+
* This class writes to System.out for debugging output.
5+
*/
36
public class SystemOutDebug extends PrintStreamDebug {
47
public SystemOutDebug() {
58
super(System.out);

0 commit comments

Comments
 (0)