Skip to content

Commit b910d80

Browse files
Modified logging (#365)
Added structured log statements throughout the system in transport layer, crypto module, serialization, API calls, etc. Added deprecation warning for logVerbosity and httpLoggingInterceptor config params. For logging configuration we advise using SLF4J implementation lib like logback or log4j2 and their config capabilities. Added new config property called customLoggers, which can by used when customer needs can not be implemented using configuration options of SLF4J implementation libs like logback or log4j2. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent f8434fe commit b910d80

File tree

170 files changed

+4366
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+4366
-361
lines changed

.pubnub.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: kotlin
2-
version: 10.5.8
2+
version: 10.6.0
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-10.5.8-all.jar
6+
- build/libs/pubnub-kotlin-10.6.0-all.jar
77
sdks:
88
-
99
type: library
@@ -23,8 +23,8 @@ sdks:
2323
-
2424
distribution-type: library
2525
distribution-repository: maven
26-
package-name: pubnub-kotlin-10.5.8
27-
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.5.8/pubnub-kotlin-10.5.8.jar
26+
package-name: pubnub-kotlin-10.6.0
27+
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.6.0/pubnub-kotlin-10.6.0.jar
2828
supported-platforms:
2929
supported-operating-systems:
3030
Android:
@@ -121,6 +121,15 @@ sdks:
121121
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
122122
is-required: Required
123123
changelog:
124+
- date: 2025-09-11
125+
version: v10.6.0
126+
changes:
127+
- type: feature
128+
text: "Added structured log statements throughout the system in transport layer, crypto module, serialization, API calls, etc."
129+
- type: feature
130+
text: "Added deprecation warning for logVerbosity and httpLoggingInterceptor config params. For logging configuration we advise using SLF4J implementation lib like logback or log4j2 and their config capabilities."
131+
- type: feature
132+
text: "Added new config property called customLoggers, which can bu used when customer needs can not be implemented using configuration options of SLF4J implementation libs like logback or log4j2."
124133
- date: 2025-08-06
125134
version: v10.5.8
126135
changes:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v10.6.0
2+
September 11 2025
3+
4+
#### Added
5+
- Added structured log statements throughout the system in transport layer, crypto module, serialization, API calls, etc.
6+
- Added deprecation warning for logVerbosity and httpLoggingInterceptor config params. For logging configuration we advise using SLF4J implementation lib like logback or log4j2 and their config capabilities.
7+
- Added new config property called customLoggers, which can bu used when customer needs can not be implemented using configuration options of SLF4J implementation libs like logback or log4j2.
8+
19
## v10.5.8
210
August 06 2025
311

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2020
<dependency>
2121
<groupId>com.pubnub</groupId>
2222
<artifactId>pubnub-kotlin</artifactId>
23-
<version>10.5.8</version>
23+
<version>10.6.0</version>
2424
</dependency>
2525
```
2626

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RELEASE_SIGNING_ENABLED=true
1818
SONATYPE_HOST=DEFAULT
1919
SONATYPE_AUTOMATIC_RELEASE=false
2020
GROUP=com.pubnub
21-
VERSION_NAME=10.5.8
21+
VERSION_NAME=10.6.0
2222
POM_PACKAGING=jar
2323

2424
POM_NAME=PubNub SDK

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/v2/PNConfiguration.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.pubnub.api.UserId
44
import com.pubnub.api.crypto.CryptoModule
55
import com.pubnub.api.enums.PNHeartbeatNotificationOptions
66
import com.pubnub.api.enums.PNLogVerbosity
7+
import com.pubnub.api.logging.CustomLogger
78
import com.pubnub.api.retry.RetryConfiguration
89
import okhttp3.Authenticator
910
import okhttp3.CertificatePinner
@@ -91,6 +92,13 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {
9192
/**
9293
* Set to [PNLogVerbosity.BODY] to enable logging of network traffic, otherwise se to [PNLogVerbosity.NONE].
9394
*/
95+
@Deprecated(
96+
message = "LogVerbosity setting is deprecated and will be removed in future versions. " +
97+
"For logging configuration:\n" +
98+
"1. Use an SLF4J implementation (recommended)\n" +
99+
"2. Or implement CustomLogger interface and set via customLoggers property",
100+
level = DeprecationLevel.WARNING
101+
)
94102
val logVerbosity: PNLogVerbosity
95103

96104
/**
@@ -248,6 +256,10 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {
248256
*
249257
* @see [HttpLoggingInterceptor]
250258
*/
259+
@Deprecated(
260+
message = "This setting is deprecated. Use customLoggers instead",
261+
level = DeprecationLevel.WARNING
262+
)
251263
val httpLoggingInterceptor: HttpLoggingInterceptor?
252264

253265
/**
@@ -301,6 +313,12 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {
301313
*/
302314
val managePresenceListManually: Boolean
303315

316+
/**
317+
* Custom loggers list for creating additional logger instances.
318+
* Use it if your slf4j implementation like logback, log4j2, etc. can't meet your specific logging requirements.
319+
*/
320+
val customLoggers: List<CustomLogger>?
321+
304322
override fun build(): PNConfiguration
305323

306324
override fun setUserId(userId: UserId): Builder
@@ -337,6 +355,13 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {
337355
/**
338356
* Set to [PNLogVerbosity.BODY] to enable logging of network traffic, otherwise se to [PNLogVerbosity.NONE].
339357
*/
358+
@Deprecated(
359+
message = "LogVerbosity setting is deprecated and will be removed in future versions. " +
360+
"For logging configuration:\n" +
361+
"1. Use an SLF4J implementation (recommended)\n" +
362+
"2. Or implement CustomLogger interface and set via customLoggers property",
363+
level = DeprecationLevel.WARNING
364+
)
340365
fun logVerbosity(logVerbosity: PNLogVerbosity): Builder
341366

342367
/**
@@ -479,6 +504,10 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {
479504
*
480505
* @see [HttpLoggingInterceptor]
481506
*/
507+
@Deprecated(
508+
message = "This setting is deprecated. Use customLoggers instead",
509+
level = DeprecationLevel.WARNING
510+
)
482511
fun httpLoggingInterceptor(httpLoggingInterceptor: HttpLoggingInterceptor?): Builder
483512

484513
/**
@@ -533,6 +562,12 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {
533562
* @see PNConfigurationImpl.heartbeatInterval
534563
*/
535564
fun managePresenceListManually(managePresenceListManually: Boolean): Builder
565+
566+
/**
567+
* Custom loggers list for creating additional logger instances.
568+
* Use it if your slf4j implementation like logback, log4j2, etc. can't meet your specific logging requirements.
569+
*/
570+
fun customLoggers(customLoggers: List<CustomLogger>?): Builder
536571
}
537572
}
538573

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.pubnub.api.integration;
2+
3+
import com.pubnub.api.PubNubException;
4+
import com.pubnub.api.UserId;
5+
import com.pubnub.api.integration.util.BaseIntegrationTest;
6+
import com.pubnub.api.integration.util.CustomLoggerTestImpl;
7+
import com.pubnub.api.integration.util.ITTestConfig;
8+
import com.pubnub.api.integration.util.RandomGenerator;
9+
import com.pubnub.api.java.PubNub;
10+
import com.pubnub.api.java.v2.PNConfiguration;
11+
import com.pubnub.api.logging.LogMessageContent;
12+
import com.pubnub.api.logging.LogMessageType;
13+
import org.aeonbits.owner.ConfigFactory;
14+
import org.junit.Test;
15+
16+
import java.util.Collections;
17+
import java.util.UUID;
18+
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertTrue;
21+
22+
public class LoggingIntegrationTest extends BaseIntegrationTest {
23+
final ITTestConfig itTestConfig = ConfigFactory.create(ITTestConfig.class, System.getenv());
24+
25+
@Test
26+
public void testCanLogMessagesUsingCustomLogger() throws PubNubException, InterruptedException {
27+
// Clear any previous messages
28+
CustomLoggerTestImpl.clear();
29+
30+
String expectedUuid = UUID.randomUUID().toString();
31+
String expectedChannel = "test-channel-" + RandomGenerator.newValue(8);
32+
33+
PNConfiguration.Builder configBuilder = PNConfiguration.builder(
34+
new UserId(expectedUuid),
35+
itTestConfig.subscribeKey()
36+
);
37+
configBuilder.publishKey(itTestConfig.publishKey());
38+
configBuilder.customLoggers(Collections.singletonList(new CustomLoggerTestImpl()));
39+
40+
PubNub pubNub = PubNub.create(configBuilder.build());
41+
42+
// Publish a message to generate logs
43+
pubNub.publish()
44+
.channel(expectedChannel)
45+
.message(generatePayload())
46+
.customMessageType("myType")
47+
.sync();
48+
49+
// Verify logging
50+
assertFalse("Should have received string messages", CustomLoggerTestImpl.stringMessages.isEmpty());
51+
assertFalse("Should have received LogMessage objects", CustomLoggerTestImpl.logMessages.isEmpty());
52+
53+
// Verify content - string messages
54+
assertTrue(
55+
"Should have called publish on the expected channel",
56+
CustomLoggerTestImpl.stringMessages.stream().anyMatch(msg ->
57+
msg.contains("PublishEndpoint") && msg.contains(expectedChannel)
58+
)
59+
);
60+
61+
assertTrue(
62+
"Should have called publish on the expected channel",
63+
CustomLoggerTestImpl.stringMessages.stream().anyMatch(msg ->
64+
msg.contains("NetworkRequest") && msg.contains(expectedChannel)
65+
)
66+
);
67+
68+
assertTrue(
69+
"Should have called publish on the expected channel",
70+
CustomLoggerTestImpl.stringMessages.stream().anyMatch(msg ->
71+
msg.contains("NetworkResponse") && msg.contains(expectedChannel)
72+
)
73+
);
74+
75+
// Verify content - LogMessage objects
76+
assertTrue(
77+
"Should have called publish on the expected channel",
78+
CustomLoggerTestImpl.logMessages.stream().anyMatch(msg ->
79+
msg.getType() == LogMessageType.OBJECT &&
80+
msg.getLocation().contains("PublishEndpoint") &&
81+
(msg.getMessage() instanceof LogMessageContent.Object) &&
82+
expectedChannel.equals(((LogMessageContent.Object) msg.getMessage()).getMessage().get("channel"))
83+
)
84+
);
85+
86+
assertTrue(
87+
"Should have called publish API. LogMessage type should be NETWORK_REQUEST",
88+
CustomLoggerTestImpl.logMessages.stream().anyMatch(msg ->
89+
msg.getType() == LogMessageType.NETWORK_REQUEST &&
90+
msg.getLocation().contains("publish")
91+
)
92+
);
93+
94+
assertTrue(
95+
"Should have called publish API. LogMessage type should be NETWORK_RESPONSE",
96+
CustomLoggerTestImpl.logMessages.stream().anyMatch(msg ->
97+
msg.getType() == LogMessageType.NETWORK_RESPONSE &&
98+
msg.getLocation().contains("publish")
99+
)
100+
);
101+
102+
pubNub.destroy();
103+
}
104+
105+
}

pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/MessageActionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void onMore(List<PNMessageAction> actions) {
231231

232232
@Override
233233
public void onDone() {
234-
log.error(String.format("onDone %s", count.get()));
234+
System.out.println(String.format("onDone %s", count.get()));
235235
success.set(count.get() == messageCount);
236236
}
237237
});

pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/PNConfigurationIntegrationTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.pubnub.api.PubNubException;
44
import com.pubnub.api.UserId;
5+
import com.pubnub.api.integration.util.CustomLoggerTestImpl;
56
import com.pubnub.api.integration.util.ITTestConfig;
67
import com.pubnub.api.integration.util.Utils;
78
import com.pubnub.api.java.PubNub;
@@ -11,6 +12,8 @@
1112
import org.junit.Assert;
1213
import org.junit.Test;
1314

15+
import java.util.Arrays;
16+
1417
public class PNConfigurationIntegrationTests {
1518
final ITTestConfig itTestConfig = ConfigFactory.create(ITTestConfig.class, System.getenv());
1619

@@ -35,12 +38,14 @@ public void createConfigurationWithConfigurationActionBlock() throws PubNubExcep
3538
String expectedUuid = PubNub.generateUUID();
3639

3740
PNConfiguration.Builder configBuilder = PNConfiguration.builder(new UserId(expectedUuid), itTestConfig.subscribeKey())
38-
.publishKey(itTestConfig.publishKey());
41+
.publishKey(itTestConfig.publishKey())
42+
.customLoggers( Arrays.asList(new CustomLoggerTestImpl()));
3943
PubNub pubNub = PubNub.create(configBuilder.build());
4044

4145
Assert.assertEquals(expectedUuid, pubNub.getConfiguration().getUserId().getValue());
4246
Assert.assertEquals(itTestConfig.subscribeKey(), pubNub.getConfiguration().getSubscribeKey());
4347
Assert.assertEquals(itTestConfig.publishKey(), pubNub.getConfiguration().getPublishKey());
48+
Assert.assertTrue(pubNub.getConfiguration().getCustomLoggers().get(0) instanceof CustomLoggerTestImpl);
4449
}
4550

4651
@Test

pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/channel/ChannelMetadataIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.jetbrains.annotations.NotNull;
1313
import org.junit.After;
1414
import org.junit.Test;
15-
import org.slf4j.Logger;
16-
import org.slf4j.LoggerFactory;
1715

1816
import java.util.ArrayList;
1917
import java.util.HashMap;
@@ -35,7 +33,6 @@
3533
import static org.junit.Assert.assertNotNull;
3634

3735
public class ChannelMetadataIT extends ObjectsApiBaseIT {
38-
private static final Logger LOG = LoggerFactory.getLogger(ChannelMetadataIT.class);
3936
private static final int NUMBER_OF_RANDOM_TEST_NAMES = 10;
4037
private static final int FETCH_LIMIT = 3;
4138

@@ -272,7 +269,7 @@ public void cleanUp() {
272269
.channel(setChannelMetadataResult.getData().getId())
273270
.sync();
274271
} catch (Exception e) {
275-
LOG.warn("Could not cleanup {}", setChannelMetadataResult, e);
272+
System.out.printf("Could not cleanup {}", setChannelMetadataResult);
276273
}
277274
});
278275
}

pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/members/ChannelMembersIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.jetbrains.annotations.Nullable;
1818
import org.junit.After;
1919
import org.junit.Test;
20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
2220

2321
import java.util.ArrayList;
2422
import java.util.Arrays;
@@ -48,7 +46,6 @@
4846
import static org.junit.Assert.assertTrue;
4947

5048
public class ChannelMembersIT extends ObjectsApiBaseIT {
51-
private static final Logger LOG = LoggerFactory.getLogger(ChannelMembersIT.class);
5249
private static final String STATUS_01 = "myStatus01";
5350
private static final String TYPE_01 = "myType01" + random();
5451
private static final String TYPE_02 = "myType02" + random();
@@ -475,7 +472,7 @@ public void cleanUp() {
475472
.sync();
476473

477474
} catch (Exception e) {
478-
LOG.warn("Could not cleanup {}", createdMembers, e);
475+
System.out.printf("Could not cleanup %s%n", createdMembers);
479476
}
480477
}
481478
}

0 commit comments

Comments
 (0)