Skip to content

Commit

Permalink
Fixing log calls (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis authored Mar 16, 2023
1 parent 03ffd64 commit 5778eb2
Show file tree
Hide file tree
Showing 35 changed files with 612 additions and 356 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
22.09.2
* Fixed internal log calls that did not respect the configured log level and did not work with the log listener.

22.09.1
* Adding a way to override metrics sent by "begin session" requests.
* Fixed bug where "setApplicationVersion" would not set the application version in metrics
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# org.gradle.parallel=true

# RELEASE FIELD SECTION
VERSION_NAME=22.09.1
VERSION_NAME=22.09.2
GROUP=ly.count.sdk

POM_URL=https://github.com/Countly/countly-sdk-java
Expand Down
121 changes: 87 additions & 34 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* Countly configuration object.
*/
public class Config {

/**
* Logging level for {@link Log} module
*/
Expand Down Expand Up @@ -157,7 +156,7 @@ public String toString() {
}

@Override
public byte[] store() {
public byte[] store(Log L) {
ByteArrayOutputStream bytes = null;
ObjectOutputStream stream = null;
try {
Expand All @@ -169,55 +168,67 @@ public byte[] store() {
stream.close();
return bytes.toByteArray();
} catch (IOException e) {
System.out.print("[ConfigCore] Cannot serialize config" + e.toString());
if (L != null) {
L.e("[ConfigCore] Cannot serialize config" + e.toString());
}
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
System.out.print("[ConfigCore] Cannot happen" + e.toString());
if (L != null) {
L.e("[ConfigCore] Cannot happen" + e.toString());
}
}
}
if (bytes != null) {
try {
bytes.close();
} catch (IOException e) {
System.out.print("[ConfigCore] Cannot happen" + e.toString());
if (L != null) {
L.e("[ConfigCore] Cannot happen" + e.toString());
}
}
}
}
return null;
}

@Override
public boolean restore(byte[] data) {
public boolean restore(byte[] data, Log L) {
ByteArrayInputStream bytes = null;
ObjectInputStream stream = null;

try {
bytes = new ByteArrayInputStream(data);
stream = new ObjectInputStream(bytes);

Utils.reflectiveSetField(this, "realm", stream.readInt());
Utils.reflectiveSetField(this, "strategy", stream.readInt());
Utils.reflectiveSetField(this, "id", stream.readObject());
Utils.reflectiveSetField(this, "realm", stream.readInt(), L);
Utils.reflectiveSetField(this, "strategy", stream.readInt(), L);
Utils.reflectiveSetField(this, "id", stream.readObject(), L);

return true;
} catch (IOException | ClassNotFoundException e) {
System.out.print("[ConfigCore] Cannot deserialize config" + e.toString());
if (L != null) {
L.e("[ConfigCore] Cannot deserialize config" + e.toString());
}
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
System.out.print("[ConfigCore] Cannot happen" + e.toString());
if (L != null) {
L.e("[ConfigCore] Cannot happen" + e.toString());
}
}
}
if (bytes != null) {
try {
bytes.close();
} catch (IOException e) {
System.out.print("[ConfigCore] Cannot happen" + e.toString());
if (L != null) {
L.e("[ConfigCore] Cannot happen" + e.toString());
}
}
}
}
Expand All @@ -226,6 +237,8 @@ public boolean restore(byte[] data) {
}
}

protected Log configLog;

/**
* URL of Countly server
*/
Expand Down Expand Up @@ -269,7 +282,7 @@ public boolean restore(byte[] data) {
/**
* Countly SDK version to be sent in HTTP requests
*/
protected String sdkVersion = "22.09.1";
protected String sdkVersion = "22.09.2";

/**
* Countly SDK version to be sent in HTTP requests
Expand Down Expand Up @@ -576,11 +589,15 @@ public Config setDeviceIdFallbackAllowed(boolean deviceIdFallbackAllowed) {
*/
public Config enableFeatures(Config.Feature... features) {
if (features == null) {
System.out.print("[ConfigCore] Features array cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] Features array cannot be null");
}
} else {
for (Config.Feature f : features) {
if (f == null) {
System.out.print("[ConfigCore] Feature cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] Feature cannot be null");
}
} else {
this.features = this.features | f.getIndex();
}
Expand All @@ -597,11 +614,15 @@ public Config enableFeatures(Config.Feature... features) {
*/
public Config disableFeatures(Config.Feature... features) {
if (features == null) {
System.out.print("[ConfigCore] Features array cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] Features array cannot be null");
}
} else {
for (Config.Feature f : features) {
if (f == null) {
System.out.print("[ConfigCore] Feature cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] Feature cannot be null");
}
} else {
this.features = this.features & ~f.getIndex();
}
Expand Down Expand Up @@ -634,7 +655,9 @@ public Config setFeatures(Config.Feature... features) {
if (features != null && features.length > 0) {
for (int i = 0; i < features.length; i++) {
if (features[i] == null) {
System.out.print(i + "-th feature is null in setFeatures");
if (configLog != null) {
configLog.e("[ConfigCore] " + i + "-th feature is null in setFeatures");
}
} else {
this.features = this.features | features[i].index;
}
Expand All @@ -654,7 +677,9 @@ public Config setFeatures(Config.Feature... features) {
*/
public Config setDeviceIdStrategy(DeviceIdStrategy strategy, String customDeviceId) {
if (strategy == null) {
System.out.print("[ConfigCore] DeviceIdStrategy cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] DeviceIdStrategy cannot be null");
}
} else {
if (strategy == DeviceIdStrategy.CUSTOM_ID) {
return setCustomDeviceId(customDeviceId);
Expand Down Expand Up @@ -682,7 +707,9 @@ public Config setDeviceIdStrategy(DeviceIdStrategy strategy) {
*/
public Config setCustomDeviceId(String customDeviceId) {
if (Utils.isEmptyOrNull(customDeviceId)) {
System.out.print("[ConfigCore] DeviceIdStrategy.CUSTOM_ID strategy cannot be used without device id specified");
if (configLog != null) {
configLog.e("[ConfigCore] DeviceIdStrategy.CUSTOM_ID strategy cannot be used without device id specified");
}
} else {
this.customDeviceId = customDeviceId;
this.deviceIdStrategy = DeviceIdStrategy.CUSTOM_ID.index;
Expand Down Expand Up @@ -753,7 +780,9 @@ public Config setRequestQueueMaxSize(int requestQueueMaxSize) {
*/
public Config enableParameterTamperingProtection(String salt) {
if (Utils.isEmptyOrNull(salt)) {
System.out.print("[ConfigCore] Salt cannot be empty in enableParameterTamperingProtection");
if (configLog != null) {
configLog.e("[ConfigCore] Salt cannot be empty in enableParameterTamperingProtection");
}
} else {
this.salt = salt;
}
Expand All @@ -779,7 +808,9 @@ public Config setLoggingTag(String loggingTag) {
*/
public Config setLoggingLevel(LoggingLevel loggingLevel) {
if (loggingLevel == null) {
System.out.print("[ConfigCore] Logging level cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] Logging level cannot be null");
}
} else {
this.loggingLevel = loggingLevel;
}
Expand Down Expand Up @@ -825,7 +856,9 @@ public Config disableTestMode() {
*/
public Config setSendUpdateEachSeconds(int sendUpdateEachSeconds) {
if (sendUpdateEachSeconds < 0) {
System.out.print("[ConfigCore] sendUpdateEachSeconds cannot be negative");
if (configLog != null) {
configLog.e("[ConfigCore] sendUpdateEachSeconds cannot be negative");
}
} else {
this.sendUpdateEachSeconds = sendUpdateEachSeconds;
}
Expand All @@ -842,7 +875,9 @@ public Config setSendUpdateEachSeconds(int sendUpdateEachSeconds) {
*/
public Config setEventsBufferSize(int eventsBufferSize) {
if (eventsBufferSize < 0) {
System.out.print("[ConfigCore] eventsBufferSize cannot be negative");
if (configLog != null) {
configLog.e("[ConfigCore] eventsBufferSize cannot be negative");
}
} else {
this.eventsBufferSize = eventsBufferSize;
}
Expand Down Expand Up @@ -903,7 +938,9 @@ public Config setApplicationName(String name) {
*/
public Config setApplicationVersion(String version) {
if (Utils.isEmptyOrNull(version)) {
System.out.print("[ConfigCore] version cannot be empty");
if (configLog != null) {
configLog.e("[ConfigCore] version cannot be empty");
}
} else {
this.applicationVersion = version;
}
Expand All @@ -918,7 +955,9 @@ public Config setApplicationVersion(String version) {
*/
public Config setNetworkConnectTimeout(int seconds) {
if (seconds <= 0 || seconds > 300) {
System.out.print("[ConfigCore] Connection timeout must be between 0 and 300");
if (configLog != null) {
configLog.e("[ConfigCore] Connection timeout must be between 0 and 300");
}
} else {
networkConnectionTimeout = seconds;
}
Expand All @@ -933,7 +972,9 @@ public Config setNetworkConnectTimeout(int seconds) {
*/
public Config setNetworkReadTimeout(int seconds) {
if (seconds <= 0 || seconds > 300) {
System.out.print("[ConfigCore] Read timeout must be between 0 and 300");
if (configLog != null) {
configLog.e("[ConfigCore] Read timeout must be between 0 and 300");
}
} else {
networkReadTimeout = seconds;
}
Expand All @@ -949,7 +990,9 @@ public Config setNetworkReadTimeout(int seconds) {
*/
public Config setNetworkRequestCooldown(int milliseconds) {
if (milliseconds < 0 || milliseconds > 30000) {
System.out.print("[ConfigCore] Request cooldown must be between 0 and 30000");
if (configLog != null) {
configLog.e("[ConfigCore] Request cooldown must be between 0 and 30000");
}
} else {
networkRequestCooldown = milliseconds;
}
Expand All @@ -965,7 +1008,9 @@ public Config setNetworkRequestCooldown(int milliseconds) {
*/
public Config setNetworkImportantRequestCooldown(int milliseconds) {
if (milliseconds < 0 || milliseconds > 30) {
System.out.print("[ConfigCore] Important request cooldown must be between 0 and 30");
if (configLog != null) {
configLog.e("[ConfigCore] Important request cooldown must be between 0 and 30");
}
} else {
networkImportantRequestCooldown = milliseconds;
}
Expand Down Expand Up @@ -993,7 +1038,9 @@ public Config setNetworkImportantRequestCooldown(int milliseconds) {
*/
public Config addPublicKeyPin(String pemEncodedPublicKey) {
if (Utils.isEmptyOrNull(pemEncodedPublicKey)) {
System.out.print("[ConfigCore] pemEncodedPublicKey cannot be empty");
if (configLog != null) {
configLog.e("[ConfigCore] pemEncodedPublicKey cannot be empty");
}
} else {
if (publicKeyPins == null) {
publicKeyPins = new HashSet<>();
Expand Down Expand Up @@ -1025,7 +1072,9 @@ public Config addPublicKeyPin(String pemEncodedPublicKey) {
*/
public Config addCertificatePin(String pemEncodedCertificate) {
if (Utils.isEmptyOrNull(pemEncodedCertificate)) {
System.out.print("[ConfigCore] pemEncodedCertificate cannot be empty");
if (configLog != null) {
configLog.e("[ConfigCore] pemEncodedCertificate cannot be empty");
}
} else {
if (certificatePins == null) {
certificatePins = new HashSet<>();
Expand Down Expand Up @@ -1073,7 +1122,9 @@ public Config disableANRCrashReporting() {
*/
public Config setCrashProcessorClass(Class<? extends CrashProcessor> crashProcessorClass) {
if (crashProcessorClass == null) {
System.out.print("[ConfigCore] crashProcessorClass cannot be null");
if (configLog != null) {
configLog.e("[ConfigCore] crashProcessorClass cannot be null");
}
} else {
this.crashProcessorClass = crashProcessorClass.getName();
}
Expand Down Expand Up @@ -1246,9 +1297,10 @@ public boolean isFeatureEnabled(int feature) {
}

/**
* Getter for {@link #applicationName}
* Getter for applicationName
*
* @return applicationName value
* @deprecated will return empty string
* @return {@link #applicationName} value
*/
public String getApplicationName() {
return "";
Expand Down Expand Up @@ -1410,6 +1462,7 @@ public boolean requiresConsent() {

/**
* Mechanism for overriding metrics that are sent together with "begin session" requests and remote config
*
* @param metricOverride map of values to be used for override
* @return {@code this} instance for method chaining
*/
Expand Down
Loading

0 comments on commit 5778eb2

Please sign in to comment.