Skip to content

Commit 0c93e44

Browse files
committed
setLoggingLevel
1 parent 848eea8 commit 0c93e44

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
id 'signing'
99
}
1010

11-
def jarVersion = "1.0.12"
11+
def jarVersion = "1.0.13"
1212
group = 'io.nats'
1313

1414
def isMerge = System.getenv("BUILD_EVENT") == "push"

src/main/java/nats/io/NatsServerRunner.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.List;
22+
import java.util.logging.Level;
2223
import java.util.logging.Logger;
2324
import java.util.regex.Matcher;
2425
import java.util.regex.Pattern;
@@ -27,7 +28,19 @@
2728

2829
public class NatsServerRunner implements AutoCloseable {
2930

30-
private static final Logger LOGGER = Logger.getLogger(NatsServerRunner.class.getName());
31+
private static Logger LOGGER;
32+
33+
static {
34+
LOGGER = Logger.getLogger(NatsServerRunner.class.getName());
35+
}
36+
37+
public static void setLogger(Logger logger) {
38+
LOGGER = logger;
39+
}
40+
41+
public static void setLoggingLevel(Level loggingLevel) {
42+
LOGGER.setLevel(loggingLevel);
43+
}
3144

3245
private final int _port;
3346
private final File configFile;
@@ -255,7 +268,6 @@ public NatsServerRunner(String[] customArgs, int port, boolean debug) throws IOE
255268
this(port, debug, false, null, null, customArgs);
256269
}
257270

258-
259271
/**
260272
* Construct and start the Nats Server runner with options
261273
*

src/test/java/nats/io/NatsServerRunnerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.util.Arrays;
22+
import java.util.logging.Level;
2223
import java.util.stream.Stream;
2324

2425
public class NatsServerRunnerTest extends TestBase {
@@ -87,4 +88,14 @@ public void testWithConfig(String configFile, boolean checkConnect) throws IOExc
8788
}
8889
}
8990
}
91+
92+
// THIS TEST IS RUN MANUALLY. THERE SHOULD BE NO SERVER OUTPUT
93+
// COMMENT OUT the setLoggingLevel to see the output appear.
94+
@Test
95+
public void testLoggingLevel() throws IOException, InterruptedException {
96+
NatsServerRunner.setLoggingLevel(Level.SEVERE);
97+
try (NatsServerRunner runner = new NatsServerRunner()) {
98+
connect(runner);
99+
}
100+
}
90101
}

0 commit comments

Comments
 (0)