Skip to content

Commit 2387030

Browse files
committed
added back display level static default
1 parent b6d7665 commit 2387030

File tree

4 files changed

+110
-14
lines changed

4 files changed

+110
-14
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.1.0"
11+
def jarVersion = "1.1.1"
1212
group = 'io.nats'
1313

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

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class NatsServerRunner implements AutoCloseable {
3939
public static long DEFAULT_RUN_CHECK_WAIT = 100;
4040
public static int DEFAULT_RUN_CHECK_TRIES = 3;
4141

42+
private static Level DefaultDisplayLevel = Level.ALL;
43+
44+
public static void setDefaultDisplayLevel(Level defaultDisplayLevel) {
45+
DefaultDisplayLevel = defaultDisplayLevel;
46+
}
47+
4248
private final String _executablePath;
4349
private final Logger _displayOut;
4450
private final int _port;
@@ -307,7 +313,10 @@ public NatsServerRunner(int port, boolean debug, boolean jetstream, String confi
307313
_port = b.port == null || b.port <= 0 ? nextPort() : b.port;
308314

309315
_displayOut = b.displayOut == null ? Logger.getLogger(NatsServerRunner.class.getName()) : b.displayOut;
310-
if (b.displayOutLevel != null) {
316+
if (b.displayOutLevel == null) {
317+
_displayOut.setLevel(DefaultDisplayLevel);
318+
}
319+
else {
311320
_displayOut.setLevel(b.displayOutLevel);
312321
}
313322

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2022 The NATS Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at:
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
package nats.io;
14+
15+
import org.junit.jupiter.api.Test;
16+
17+
import java.io.IOException;
18+
import java.util.logging.Level;
19+
20+
public class DisplayLevelTest extends TestBase {
21+
22+
// RUN THIS TEST MANUALLY TO SEE THE PROPER SERVER OUTPUT
23+
@Test
24+
public void testDisplayOutLevel() throws IOException, InterruptedException {
25+
System.out.println("------------------------------------------------------------------------------");
26+
System.out.println("THIS SHOULD SHOW EVERYTHING. Level:ALL (Default), No Error.");
27+
System.out.println("------------------------------------------------------------------------------");
28+
try (NatsServerRunner runner = NatsServerRunner.builder()
29+
.build())
30+
{
31+
connect(runner);
32+
}
33+
catch (Exception ignore) {}
34+
35+
System.out.println("------------------------------------------------------------------------------");
36+
System.out.println("THIS SHOULD ALSO SHOW EVERYTHING. Level:INFO, No Error.");
37+
System.out.println("------------------------------------------------------------------------------");
38+
try (NatsServerRunner runner = NatsServerRunner.builder()
39+
.displayOutLevel(Level.INFO)
40+
.build())
41+
{
42+
connect(runner);
43+
}
44+
catch (Exception ignore) {}
45+
46+
Thread.sleep(100);
47+
System.out.println("------------------------------------------------------------------------------");
48+
System.out.println("THIS SHOULD SHOW THE ERROR ONLY. Level:SEVERE, Yes Error.");
49+
System.out.println("------------------------------------------------------------------------------");
50+
try (NatsServerRunner runner = NatsServerRunner.builder()
51+
.configFilePath("not-a-real-path")
52+
.displayOutLevel(Level.SEVERE)
53+
.build())
54+
{
55+
connect(runner);
56+
}
57+
catch (Exception ignore) {}
58+
59+
Thread.sleep(100);
60+
System.out.println("------------------------------------------------------------------------------");
61+
System.out.println("THIS SHOULD ALSO SHOW THE ERROR ONLY. Level:INFO, Yes Error.");
62+
System.out.println("------------------------------------------------------------------------------");
63+
try (NatsServerRunner runner = NatsServerRunner.builder()
64+
.configFilePath("not-a-real-path")
65+
.displayOutLevel(Level.INFO)
66+
.build())
67+
{
68+
connect(runner);
69+
}
70+
catch (Exception ignore) {}
71+
72+
Thread.sleep(100);
73+
System.out.println("------------------------------------------------------------------------------");
74+
System.out.println("THIS SHOULD SHOW NOTHING. Level:OFF, Yes Error.");
75+
System.out.println("------------------------------------------------------------------------------");
76+
try (NatsServerRunner runner = NatsServerRunner.builder()
77+
.configFilePath("not-a-real-path")
78+
.displayOutLevel(Level.OFF)
79+
.build())
80+
{
81+
connect(runner);
82+
}
83+
catch (Exception ignore) {}
84+
85+
Thread.sleep(100);
86+
System.out.println("------------------------------------------------------------------------------");
87+
System.out.println("THIS SHOULD ALSO SHOW NOTHING. Level:SEVERE, No Error.");
88+
System.out.println("------------------------------------------------------------------------------");
89+
try (NatsServerRunner runner = NatsServerRunner.builder()
90+
.displayOutLevel(Level.SEVERE)
91+
.build())
92+
{
93+
connect(runner);
94+
}
95+
catch (Exception ignore) {}
96+
97+
System.out.println("------------------------------------------------------------------------------");
98+
}
99+
}

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

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

2020
import java.io.IOException;
2121
import java.util.Arrays;
22-
import java.util.logging.Level;
2322
import java.util.stream.Stream;
2423

2524
public class NatsServerRunnerTest extends TestBase {
@@ -134,15 +133,4 @@ public void testWithConfigBuilder(String configFile, boolean checkConnect) throw
134133
_testWithConfig(configFile, checkConnect, configInserts, runner);
135134
}
136135
}
137-
138-
// RUN THIS TEST MANUALLY TO SEE THAT THERE IS NO SERVER OUTPUT TO THE CONSOLE
139-
// COMMENT OUT THE .displayOutLevel(Level.SEVERE) TO SEE THE OUTPUT APPEAR.
140-
@Test
141-
public void testDisplayOutLevel() throws IOException, InterruptedException {
142-
try (NatsServerRunner runner = NatsServerRunner.builder()
143-
.displayOutLevel(Level.SEVERE)
144-
.build()) {
145-
connect(runner);
146-
}
147-
}
148136
}

0 commit comments

Comments
 (0)