Skip to content

Commit 7dd07ce

Browse files
committed
Rework DB2 logging (#1652)
- in production code, use Vert.x internal logging API instead of JUL - in test code, standardize on log4j2 instead of a mix of sysout and log4j1 Set log level to only see warnings and errors by default Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent 8bdb7a5 commit 7dd07ce

28 files changed

+522
-419
lines changed

vertx-db2-client/pom.xml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
<?xml version="1.0"?>
22
<!--
3-
~ Copyright (C) 2019 IBM Corporation
3+
~ Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
44
~
5-
~ Licensed under the Apache License, Version 2.0 (the "License");
6-
~ you may not use this file except in compliance with the License.
7-
~ You may obtain a copy of the License at
8-
~
9-
~ http://www.apache.org/licenses/LICENSE-2.0
10-
~
11-
~ Unless required by applicable law or agreed to in writing, software
12-
~ distributed under the License is distributed on an "AS IS" BASIS,
13-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
~ See the License for the specific language governing permissions and
15-
~ limitations under the License.
5+
~ This program and the accompanying materials are made available under the
6+
~ terms of the Eclipse Public License 2.0 which is available at
7+
~ http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
8+
~ which is available at https://www.apache.org/licenses/LICENSE-2.0.
169
~
10+
~ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1711
-->
1812
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1913

@@ -61,12 +55,34 @@
6155
<version>11.1.4.4</version>
6256
<scope>test</scope>
6357
</dependency>
58+
<!-- SLF4J API for test code and Testcontainers -->
6459
<dependency>
6560
<groupId>org.slf4j</groupId>
66-
<artifactId>slf4j-log4j12</artifactId>
67-
<version>1.7.26</version>
61+
<artifactId>slf4j-api</artifactId>
62+
<version>2.0.9</version>
63+
<scope>test</scope>
64+
</dependency>
65+
<!-- Log4j 2 API -->
66+
<dependency>
67+
<groupId>org.apache.logging.log4j</groupId>
68+
<artifactId>log4j-api</artifactId>
69+
<version>2.20.0</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<!-- Log4j 2 Core -->
73+
<dependency>
74+
<groupId>org.apache.logging.log4j</groupId>
75+
<artifactId>log4j-core</artifactId>
76+
<version>2.20.0</version>
77+
<scope>test</scope>
78+
</dependency>
79+
<!-- Log4j 2 SLF4J Binding -->
80+
<dependency>
81+
<groupId>org.apache.logging.log4j</groupId>
82+
<artifactId>log4j-slf4j2-impl</artifactId>
83+
<version>2.20.0</version>
6884
<scope>test</scope>
69-
</dependency>
85+
</dependency>
7086
<dependency>
7187
<groupId>io.vertx</groupId>
7288
<artifactId>vertx-sql-client</artifactId>

vertx-db2-client/src/main/java/io/vertx/db2client/impl/codec/RowResultDecoder.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
/*
2-
* Copyright (C) 2019,2020 IBM Corporation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1510
*/
1611
package io.vertx.db2client.impl.codec;
1712

18-
import java.math.BigDecimal;
19-
import java.util.stream.Collector;
20-
2113
import io.netty.buffer.ByteBuf;
2214
import io.vertx.core.internal.logging.Logger;
2315
import io.vertx.core.internal.logging.LoggerFactory;
@@ -29,6 +21,9 @@
2921
import io.vertx.sqlclient.impl.RowDecoder;
3022
import io.vertx.sqlclient.internal.RowInternal;
3123

24+
import java.math.BigDecimal;
25+
import java.util.stream.Collector;
26+
3227
class RowResultDecoder<C, R> extends RowDecoder<C, R> {
3328

3429
private static final Logger LOG = LoggerFactory.getLogger(RowResultDecoder.class);
@@ -67,8 +62,10 @@ protected boolean decodeRow(int len, ByteBuf in, Row row) {
6762
// TODO: Remove this once all getObject paths are implemented safely
6863
// or add unit tests for this in the DRDA project
6964
if (startingIdx != endingIdx) {
70-
System.out.println("WARN: Reader index changed while getting data. Changed from " + startingIdx + " to "
65+
if (LOG.isWarnEnabled()) {
66+
LOG.warn("Reader index changed while getting data. Changed from " + startingIdx + " to "
7167
+ endingIdx + " while obtaining object " + o);
68+
}
7269
}
7370
if (o instanceof BigDecimal) {
7471
o = Numeric.create((BigDecimal) o);

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/ClientTypes.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
/*
2-
* Copyright (C) 2019,2020 IBM Corporation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1510
*/
1611
package io.vertx.db2client.impl.drda;
1712

13+
import io.netty.buffer.ByteBuf;
14+
1815
import java.math.BigDecimal;
1916
import java.math.BigInteger;
2017
import java.sql.RowId;
@@ -24,8 +21,6 @@
2421
import java.time.LocalTime;
2522
import java.util.UUID;
2623

27-
import io.netty.buffer.ByteBuf;
28-
2924
// This enumeration of types represents the typing scheme used by our jdbc driver.
3025
// Once this is finished, we need to review our switches to make sure they are exhaustive
3126
/**
@@ -250,8 +245,6 @@ static public int mapDB2TypeToDriverType(boolean isDescribed, int sqlType, long
250245
case DRDAConstants.DB2_SQLTYPE_ROWID:
251246
return ROWID;
252247
default:
253-
// TODO: log a warning here
254-
// System.out.println("WARN: Unknown DB2 type encountered: " + sqlType);
255248
return 0;
256249
}
257250
}

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/DB2Package.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
/*
2-
* Copyright (C) 2020 IBM Corporation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1510
*/
1611
package io.vertx.db2client.impl.drda;
1712

13+
import io.vertx.core.internal.logging.Logger;
14+
import io.vertx.core.internal.logging.LoggerFactory;
15+
1816
import java.util.concurrent.ConcurrentLinkedDeque;
1917
import java.util.concurrent.atomic.AtomicInteger;
20-
import java.util.logging.Level;
21-
import java.util.logging.Logger;
2218

2319
/**
2420
* ## Packages
@@ -42,7 +38,7 @@
4238
*/
4339
public class DB2Package {
4440

45-
private static final Logger LOG = Logger.getLogger(DB2Package.class.getName());
41+
private static final Logger LOG = LoggerFactory.getLogger(DB2Package.class);
4642

4743
private static final int MAX_SECTIONS_SMALL_PKG = 64;
4844
private static final int MAX_SECTIONS_LARGE_PKG = 384;
@@ -77,15 +73,17 @@ Section getFreeSection() {
7773
Section s = freeSections.poll();
7874
if (s != null) {
7975
s.use();
80-
if (LOG.isLoggable(Level.FINE))
81-
LOG.fine("Using existing section " + s);
76+
if (LOG.isDebugEnabled()) {
77+
LOG.debug("Using existing section " + s);
78+
}
8279
return s;
8380
}
8481

8582
int sectionNumber = nextAvailableSectionNumber.getAndIncrement();
8683
if (sectionNumber > maxSections) {
87-
if (LOG.isLoggable(Level.FINE))
88-
LOG.fine("All sections in use for package " + this);
84+
if (LOG.isDebugEnabled()) {
85+
LOG.debug("All sections in use for package " + this);
86+
}
8987
return null;
9088
}
9189

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/DRDAConnectResponse.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
/*
2-
* Copyright (C) 2019,2020 IBM Corporation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1510
*/
1611
package io.vertx.db2client.impl.drda;
1712

18-
import java.sql.Connection;
19-
import java.util.ArrayList;
20-
import java.util.List;
21-
import java.util.Objects;
22-
2313
import io.netty.buffer.ByteBuf;
14+
import io.vertx.core.internal.logging.Logger;
15+
import io.vertx.core.internal.logging.LoggerFactory;
2416
import io.vertx.db2client.DB2Exception;
2517
import io.vertx.db2client.impl.DB2DatabaseMetadata;
2618

19+
import java.sql.Connection;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
2723
public class DRDAConnectResponse extends DRDAResponse {
2824

25+
private static final Logger logger = LoggerFactory.getLogger(DRDAConnectResponse.class);
26+
2927
public DRDAConnectResponse(ByteBuf buffer, ConnectionMetaData metadata) {
3028
super(buffer, metadata);
3129
}
@@ -216,8 +214,9 @@ private void parseVALNSPRM() {
216214
if (peekCP == CodePoint.SRVDGN) {
217215
foundInPass = true;
218216
String serverDiagnostics = parseSRVDGN();
219-
// TODO: Log this as a warning
220-
System.out.println("Server diagnostics: " + serverDiagnostics);
217+
if (logger.isDebugEnabled()) {
218+
logger.debug("Server diagnostics: " + serverDiagnostics);
219+
}
221220
peekCP = peekCodePoint();
222221
}
223222

@@ -307,8 +306,7 @@ private void parseSYNTAXRM() {
307306
if (peekCP == CodePoint.SRVDGN) {
308307
foundInPass = true;
309308
String serverDiagnostics = parseSRVDGN();
310-
// TODO: Log this as a warning
311-
System.out.println("Server diagnostics: " + serverDiagnostics);
309+
logger.debug("Server diagnostics: " + serverDiagnostics);
312310
peekCP = peekCodePoint();
313311
}
314312

@@ -1828,7 +1826,7 @@ private void parseMGRLVLLS() {
18281826
// the managerCount should be equal to the same number of
18291827
// managers sent on the excsat.
18301828

1831-
// System.out.println("Database server attributes:");
1829+
18321830
// read each of the manager levels returned from the server.
18331831
for (int i = 0; i < managerCount; i++) {
18341832

@@ -1841,25 +1839,27 @@ private void parseMGRLVLLS() {
18411839
// for this driver. Also make sure unexpected managers are not returned.
18421840
switch (managerCodePoint) {
18431841
case CodePoint.AGENT:
1844-
// System.out.println(" AGENT=" + managerLevel);
1842+
18451843
// break;
18461844
case CodePoint.SQLAM:
1847-
// System.out.println(" SQLAM=" + managerLevel);
1845+
18481846
// break;
18491847
case CodePoint.UNICODEMGR:
1850-
// System.out.println(" UNICODEMGR=" + managerLevel);
1848+
18511849
// break;
18521850
case CodePoint.RDB:
1853-
// System.out.println(" RDB=" + managerLevel);
1851+
18541852
// break;
18551853
case CodePoint.SECMGR:
1856-
// System.out.println(" SECMGR=" + managerLevel);
1854+
18571855
// break;
18581856
case CodePoint.CMNTCPIP:
1859-
// System.out.println(" CMNTCPIP=" + managerLevel);
1857+
18601858
break;
18611859
default:
1862-
System.out.println(" WARN: Unknown manager codepoint: 0x" + Integer.toHexString(managerCodePoint));
1860+
if (logger.isWarnEnabled()) {
1861+
logger.warn("Unknown manager codepoint: 0x" + Integer.toHexString(managerCodePoint));
1862+
}
18631863
}
18641864
}
18651865
}

0 commit comments

Comments
 (0)