Skip to content

Commit 5778eb2

Browse files
Fixing log calls (#38)
1 parent 03ffd64 commit 5778eb2

35 files changed

+612
-356
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
22.09.2
2+
* Fixed internal log calls that did not respect the configured log level and did not work with the log listener.
3+
14
22.09.1
25
* Adding a way to override metrics sent by "begin session" requests.
36
* Fixed bug where "setApplicationVersion" would not set the application version in metrics

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# org.gradle.parallel=true
1919

2020
# RELEASE FIELD SECTION
21-
VERSION_NAME=22.09.1
21+
VERSION_NAME=22.09.2
2222
GROUP=ly.count.sdk
2323

2424
POM_URL=https://github.com/Countly/countly-sdk-java

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* Countly configuration object.
2020
*/
2121
public class Config {
22-
2322
/**
2423
* Logging level for {@link Log} module
2524
*/
@@ -157,7 +156,7 @@ public String toString() {
157156
}
158157

159158
@Override
160-
public byte[] store() {
159+
public byte[] store(Log L) {
161160
ByteArrayOutputStream bytes = null;
162161
ObjectOutputStream stream = null;
163162
try {
@@ -169,55 +168,67 @@ public byte[] store() {
169168
stream.close();
170169
return bytes.toByteArray();
171170
} catch (IOException e) {
172-
System.out.print("[ConfigCore] Cannot serialize config" + e.toString());
171+
if (L != null) {
172+
L.e("[ConfigCore] Cannot serialize config" + e.toString());
173+
}
173174
} finally {
174175
if (stream != null) {
175176
try {
176177
stream.close();
177178
} catch (IOException e) {
178-
System.out.print("[ConfigCore] Cannot happen" + e.toString());
179+
if (L != null) {
180+
L.e("[ConfigCore] Cannot happen" + e.toString());
181+
}
179182
}
180183
}
181184
if (bytes != null) {
182185
try {
183186
bytes.close();
184187
} catch (IOException e) {
185-
System.out.print("[ConfigCore] Cannot happen" + e.toString());
188+
if (L != null) {
189+
L.e("[ConfigCore] Cannot happen" + e.toString());
190+
}
186191
}
187192
}
188193
}
189194
return null;
190195
}
191196

192197
@Override
193-
public boolean restore(byte[] data) {
198+
public boolean restore(byte[] data, Log L) {
194199
ByteArrayInputStream bytes = null;
195200
ObjectInputStream stream = null;
196201

197202
try {
198203
bytes = new ByteArrayInputStream(data);
199204
stream = new ObjectInputStream(bytes);
200205

201-
Utils.reflectiveSetField(this, "realm", stream.readInt());
202-
Utils.reflectiveSetField(this, "strategy", stream.readInt());
203-
Utils.reflectiveSetField(this, "id", stream.readObject());
206+
Utils.reflectiveSetField(this, "realm", stream.readInt(), L);
207+
Utils.reflectiveSetField(this, "strategy", stream.readInt(), L);
208+
Utils.reflectiveSetField(this, "id", stream.readObject(), L);
204209

205210
return true;
206211
} catch (IOException | ClassNotFoundException e) {
207-
System.out.print("[ConfigCore] Cannot deserialize config" + e.toString());
212+
if (L != null) {
213+
L.e("[ConfigCore] Cannot deserialize config" + e.toString());
214+
}
208215
} finally {
209216
if (stream != null) {
210217
try {
211218
stream.close();
212219
} catch (IOException e) {
213-
System.out.print("[ConfigCore] Cannot happen" + e.toString());
220+
if (L != null) {
221+
L.e("[ConfigCore] Cannot happen" + e.toString());
222+
}
214223
}
215224
}
216225
if (bytes != null) {
217226
try {
218227
bytes.close();
219228
} catch (IOException e) {
220-
System.out.print("[ConfigCore] Cannot happen" + e.toString());
229+
if (L != null) {
230+
L.e("[ConfigCore] Cannot happen" + e.toString());
231+
}
221232
}
222233
}
223234
}
@@ -226,6 +237,8 @@ public boolean restore(byte[] data) {
226237
}
227238
}
228239

240+
protected Log configLog;
241+
229242
/**
230243
* URL of Countly server
231244
*/
@@ -269,7 +282,7 @@ public boolean restore(byte[] data) {
269282
/**
270283
* Countly SDK version to be sent in HTTP requests
271284
*/
272-
protected String sdkVersion = "22.09.1";
285+
protected String sdkVersion = "22.09.2";
273286

274287
/**
275288
* Countly SDK version to be sent in HTTP requests
@@ -576,11 +589,15 @@ public Config setDeviceIdFallbackAllowed(boolean deviceIdFallbackAllowed) {
576589
*/
577590
public Config enableFeatures(Config.Feature... features) {
578591
if (features == null) {
579-
System.out.print("[ConfigCore] Features array cannot be null");
592+
if (configLog != null) {
593+
configLog.e("[ConfigCore] Features array cannot be null");
594+
}
580595
} else {
581596
for (Config.Feature f : features) {
582597
if (f == null) {
583-
System.out.print("[ConfigCore] Feature cannot be null");
598+
if (configLog != null) {
599+
configLog.e("[ConfigCore] Feature cannot be null");
600+
}
584601
} else {
585602
this.features = this.features | f.getIndex();
586603
}
@@ -597,11 +614,15 @@ public Config enableFeatures(Config.Feature... features) {
597614
*/
598615
public Config disableFeatures(Config.Feature... features) {
599616
if (features == null) {
600-
System.out.print("[ConfigCore] Features array cannot be null");
617+
if (configLog != null) {
618+
configLog.e("[ConfigCore] Features array cannot be null");
619+
}
601620
} else {
602621
for (Config.Feature f : features) {
603622
if (f == null) {
604-
System.out.print("[ConfigCore] Feature cannot be null");
623+
if (configLog != null) {
624+
configLog.e("[ConfigCore] Feature cannot be null");
625+
}
605626
} else {
606627
this.features = this.features & ~f.getIndex();
607628
}
@@ -634,7 +655,9 @@ public Config setFeatures(Config.Feature... features) {
634655
if (features != null && features.length > 0) {
635656
for (int i = 0; i < features.length; i++) {
636657
if (features[i] == null) {
637-
System.out.print(i + "-th feature is null in setFeatures");
658+
if (configLog != null) {
659+
configLog.e("[ConfigCore] " + i + "-th feature is null in setFeatures");
660+
}
638661
} else {
639662
this.features = this.features | features[i].index;
640663
}
@@ -654,7 +677,9 @@ public Config setFeatures(Config.Feature... features) {
654677
*/
655678
public Config setDeviceIdStrategy(DeviceIdStrategy strategy, String customDeviceId) {
656679
if (strategy == null) {
657-
System.out.print("[ConfigCore] DeviceIdStrategy cannot be null");
680+
if (configLog != null) {
681+
configLog.e("[ConfigCore] DeviceIdStrategy cannot be null");
682+
}
658683
} else {
659684
if (strategy == DeviceIdStrategy.CUSTOM_ID) {
660685
return setCustomDeviceId(customDeviceId);
@@ -682,7 +707,9 @@ public Config setDeviceIdStrategy(DeviceIdStrategy strategy) {
682707
*/
683708
public Config setCustomDeviceId(String customDeviceId) {
684709
if (Utils.isEmptyOrNull(customDeviceId)) {
685-
System.out.print("[ConfigCore] DeviceIdStrategy.CUSTOM_ID strategy cannot be used without device id specified");
710+
if (configLog != null) {
711+
configLog.e("[ConfigCore] DeviceIdStrategy.CUSTOM_ID strategy cannot be used without device id specified");
712+
}
686713
} else {
687714
this.customDeviceId = customDeviceId;
688715
this.deviceIdStrategy = DeviceIdStrategy.CUSTOM_ID.index;
@@ -753,7 +780,9 @@ public Config setRequestQueueMaxSize(int requestQueueMaxSize) {
753780
*/
754781
public Config enableParameterTamperingProtection(String salt) {
755782
if (Utils.isEmptyOrNull(salt)) {
756-
System.out.print("[ConfigCore] Salt cannot be empty in enableParameterTamperingProtection");
783+
if (configLog != null) {
784+
configLog.e("[ConfigCore] Salt cannot be empty in enableParameterTamperingProtection");
785+
}
757786
} else {
758787
this.salt = salt;
759788
}
@@ -779,7 +808,9 @@ public Config setLoggingTag(String loggingTag) {
779808
*/
780809
public Config setLoggingLevel(LoggingLevel loggingLevel) {
781810
if (loggingLevel == null) {
782-
System.out.print("[ConfigCore] Logging level cannot be null");
811+
if (configLog != null) {
812+
configLog.e("[ConfigCore] Logging level cannot be null");
813+
}
783814
} else {
784815
this.loggingLevel = loggingLevel;
785816
}
@@ -825,7 +856,9 @@ public Config disableTestMode() {
825856
*/
826857
public Config setSendUpdateEachSeconds(int sendUpdateEachSeconds) {
827858
if (sendUpdateEachSeconds < 0) {
828-
System.out.print("[ConfigCore] sendUpdateEachSeconds cannot be negative");
859+
if (configLog != null) {
860+
configLog.e("[ConfigCore] sendUpdateEachSeconds cannot be negative");
861+
}
829862
} else {
830863
this.sendUpdateEachSeconds = sendUpdateEachSeconds;
831864
}
@@ -842,7 +875,9 @@ public Config setSendUpdateEachSeconds(int sendUpdateEachSeconds) {
842875
*/
843876
public Config setEventsBufferSize(int eventsBufferSize) {
844877
if (eventsBufferSize < 0) {
845-
System.out.print("[ConfigCore] eventsBufferSize cannot be negative");
878+
if (configLog != null) {
879+
configLog.e("[ConfigCore] eventsBufferSize cannot be negative");
880+
}
846881
} else {
847882
this.eventsBufferSize = eventsBufferSize;
848883
}
@@ -903,7 +938,9 @@ public Config setApplicationName(String name) {
903938
*/
904939
public Config setApplicationVersion(String version) {
905940
if (Utils.isEmptyOrNull(version)) {
906-
System.out.print("[ConfigCore] version cannot be empty");
941+
if (configLog != null) {
942+
configLog.e("[ConfigCore] version cannot be empty");
943+
}
907944
} else {
908945
this.applicationVersion = version;
909946
}
@@ -918,7 +955,9 @@ public Config setApplicationVersion(String version) {
918955
*/
919956
public Config setNetworkConnectTimeout(int seconds) {
920957
if (seconds <= 0 || seconds > 300) {
921-
System.out.print("[ConfigCore] Connection timeout must be between 0 and 300");
958+
if (configLog != null) {
959+
configLog.e("[ConfigCore] Connection timeout must be between 0 and 300");
960+
}
922961
} else {
923962
networkConnectionTimeout = seconds;
924963
}
@@ -933,7 +972,9 @@ public Config setNetworkConnectTimeout(int seconds) {
933972
*/
934973
public Config setNetworkReadTimeout(int seconds) {
935974
if (seconds <= 0 || seconds > 300) {
936-
System.out.print("[ConfigCore] Read timeout must be between 0 and 300");
975+
if (configLog != null) {
976+
configLog.e("[ConfigCore] Read timeout must be between 0 and 300");
977+
}
937978
} else {
938979
networkReadTimeout = seconds;
939980
}
@@ -949,7 +990,9 @@ public Config setNetworkReadTimeout(int seconds) {
949990
*/
950991
public Config setNetworkRequestCooldown(int milliseconds) {
951992
if (milliseconds < 0 || milliseconds > 30000) {
952-
System.out.print("[ConfigCore] Request cooldown must be between 0 and 30000");
993+
if (configLog != null) {
994+
configLog.e("[ConfigCore] Request cooldown must be between 0 and 30000");
995+
}
953996
} else {
954997
networkRequestCooldown = milliseconds;
955998
}
@@ -965,7 +1008,9 @@ public Config setNetworkRequestCooldown(int milliseconds) {
9651008
*/
9661009
public Config setNetworkImportantRequestCooldown(int milliseconds) {
9671010
if (milliseconds < 0 || milliseconds > 30) {
968-
System.out.print("[ConfigCore] Important request cooldown must be between 0 and 30");
1011+
if (configLog != null) {
1012+
configLog.e("[ConfigCore] Important request cooldown must be between 0 and 30");
1013+
}
9691014
} else {
9701015
networkImportantRequestCooldown = milliseconds;
9711016
}
@@ -993,7 +1038,9 @@ public Config setNetworkImportantRequestCooldown(int milliseconds) {
9931038
*/
9941039
public Config addPublicKeyPin(String pemEncodedPublicKey) {
9951040
if (Utils.isEmptyOrNull(pemEncodedPublicKey)) {
996-
System.out.print("[ConfigCore] pemEncodedPublicKey cannot be empty");
1041+
if (configLog != null) {
1042+
configLog.e("[ConfigCore] pemEncodedPublicKey cannot be empty");
1043+
}
9971044
} else {
9981045
if (publicKeyPins == null) {
9991046
publicKeyPins = new HashSet<>();
@@ -1025,7 +1072,9 @@ public Config addPublicKeyPin(String pemEncodedPublicKey) {
10251072
*/
10261073
public Config addCertificatePin(String pemEncodedCertificate) {
10271074
if (Utils.isEmptyOrNull(pemEncodedCertificate)) {
1028-
System.out.print("[ConfigCore] pemEncodedCertificate cannot be empty");
1075+
if (configLog != null) {
1076+
configLog.e("[ConfigCore] pemEncodedCertificate cannot be empty");
1077+
}
10291078
} else {
10301079
if (certificatePins == null) {
10311080
certificatePins = new HashSet<>();
@@ -1073,7 +1122,9 @@ public Config disableANRCrashReporting() {
10731122
*/
10741123
public Config setCrashProcessorClass(Class<? extends CrashProcessor> crashProcessorClass) {
10751124
if (crashProcessorClass == null) {
1076-
System.out.print("[ConfigCore] crashProcessorClass cannot be null");
1125+
if (configLog != null) {
1126+
configLog.e("[ConfigCore] crashProcessorClass cannot be null");
1127+
}
10771128
} else {
10781129
this.crashProcessorClass = crashProcessorClass.getName();
10791130
}
@@ -1246,9 +1297,10 @@ public boolean isFeatureEnabled(int feature) {
12461297
}
12471298

12481299
/**
1249-
* Getter for {@link #applicationName}
1300+
* Getter for applicationName
1301+
*
1302+
* @return applicationName value
12501303
* @deprecated will return empty string
1251-
* @return {@link #applicationName} value
12521304
*/
12531305
public String getApplicationName() {
12541306
return "";
@@ -1410,6 +1462,7 @@ public boolean requiresConsent() {
14101462

14111463
/**
14121464
* Mechanism for overriding metrics that are sent together with "begin session" requests and remote config
1465+
*
14131466
* @param metricOverride map of values to be used for override
14141467
* @return {@code this} instance for method chaining
14151468
*/

0 commit comments

Comments
 (0)