Skip to content

Commit 77b95a7

Browse files
committed
Merge pull request #770 from pzygielo/downgrade-log-warnings
2 parents 02e2505 + e6e590c commit 77b95a7

File tree

2 files changed

+68
-20
lines changed

2 files changed

+68
-20
lines changed

mq/main/logger/src/main/java/com/sun/messaging/jmq/util/log/SysLogHandler.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,8 @@ public SysLogHandler() {
7373

7474
configure(facilityStr, logpidStr, logconsoleStr, identityStr, outputStr);
7575

76-
} catch (UnsatisfiedLinkError e) {
77-
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Logger.LOGGERNAME);
78-
logger.log(Level.INFO,
79-
SharedResources.getResources().getKString(SharedResources.W_LOGCHANNEL_DISABLED, this.getClass().getName(), e.getMessage()));
80-
open = false;
81-
} catch (NoClassDefFoundError e) {
82-
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Logger.LOGGERNAME);
83-
logger.log(Level.INFO,
84-
SharedResources.getResources().getKString(SharedResources.W_LOGCHANNEL_DISABLED, this.getClass().getName(), e.getMessage()));
85-
open = false;
76+
} catch (UnsatisfiedLinkError|NoClassDefFoundError e) {
77+
handleSharedLibraryError(e);
8678
}
8779
}
8880

@@ -102,19 +94,22 @@ public SysLogHandler(Properties props) {
10294

10395
configure(facilityStr, logpidStr, logconsoleStr, identityStr, outputStr);
10496

105-
} catch (UnsatisfiedLinkError e) {
106-
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Logger.LOGGERNAME);
107-
logger.log(Level.INFO,
108-
SharedResources.getResources().getKString(SharedResources.W_LOGCHANNEL_DISABLED, this.getClass().getName(), e.getMessage()));
109-
open = false;
110-
} catch (NoClassDefFoundError e) {
111-
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Logger.LOGGERNAME);
112-
logger.log(Level.INFO,
113-
SharedResources.getResources().getKString(SharedResources.W_LOGCHANNEL_DISABLED, this.getClass().getName(), e.getMessage()));
114-
open = false;
97+
} catch (UnsatisfiedLinkError|NoClassDefFoundError e) {
98+
handleSharedLibraryError(e);
11599
}
116100
}
117101

102+
private void handleSharedLibraryError(Error e) {
103+
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Logger.LOGGERNAME);
104+
logSharedLibraryError(logger, e.getMessage());
105+
open = false;
106+
}
107+
108+
static void logSharedLibraryError(java.util.logging.Logger logger, String errorMessage) {
109+
logger.log(Level.INFO,
110+
SharedResources.getResources().getKString(SharedResources.W_LOGCHANNEL_DISABLED, SysLogHandler.class.getName(), errorMessage));
111+
}
112+
118113
public static void setFacility(int f) {
119114
facility = f;
120115
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package com.sun.messaging.jmq.util.log;
18+
19+
import org.junit.jupiter.api.Nested;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.mockito.Mockito;
23+
24+
import static org.mockito.ArgumentMatchers.any;
25+
import static org.mockito.ArgumentMatchers.anyString;
26+
import static org.mockito.ArgumentMatchers.eq;
27+
28+
import java.util.logging.Level;
29+
import java.util.logging.Logger;
30+
31+
class SysLogHandlerTest {
32+
@Nested
33+
class Issue289 {
34+
@Test
35+
void testLevelForLibraryErrorLog() {
36+
Logger logger = Mockito.mock(Logger.class);
37+
38+
SysLogHandler.logSharedLibraryError(logger, "Library not found");
39+
40+
Mockito.verify(logger).log(eq(Level.INFO), anyString());
41+
}
42+
}
43+
44+
@Test
45+
void testLibraryErrorLogMessage() {
46+
Logger logger = Mockito.mock(Logger.class);
47+
String expectedLog = "[S2004]: Log output channel com.sun.messaging.jmq.util.log.SysLogHandler is disabled: Library not found (2)";
48+
49+
SysLogHandler.logSharedLibraryError(logger, "Library not found (2)");
50+
51+
Mockito.verify(logger).log(any(Level.class), eq(expectedLog));
52+
}
53+
}

0 commit comments

Comments
 (0)