Properly quote numbers in logs

This commit is contained in:
xynngh
2020-09-10 17:21:27 +04:00
parent fa5b616573
commit db33272fdc
4 changed files with 18 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import dummydomain.yetanothercallblocker.data.YacbHolder;
import static dummydomain.yetanothercallblocker.utils.StringUtils.quote;
import static java.util.Objects.requireNonNull;
public class CallMonitoringService extends Service {
@@ -125,7 +126,7 @@ public class CallMonitoringService extends Service {
@Override
public void onCallStateChanged(int state, String phoneNumber) {
LOG.info("onCallStateChanged({}, \"{}\")", state, phoneNumber);
LOG.info("onCallStateChanged({}, {})", state, quote(phoneNumber));
/*
* According to docs, an empty string may be passed if the app lacks permissions.

View File

@@ -11,6 +11,8 @@ import org.slf4j.LoggerFactory;
import dummydomain.yetanothercallblocker.data.YacbHolder;
import static dummydomain.yetanothercallblocker.utils.StringUtils.quote;
public class CallReceiver extends BroadcastReceiver {
private static final Logger LOG = LoggerFactory.getLogger(CallReceiver.class);
@@ -43,7 +45,7 @@ public class CallReceiver extends BroadcastReceiver {
String incomingNumber = intent.getStringExtra(extraIncomingNumber);
boolean hasNumberExtra = intent.hasExtra(extraIncomingNumber);
LOG.info("onReceive() extraState={}, incomingNumber={}, hasNumberExtra={}",
telephonyExtraState, incomingNumber, hasNumberExtra);
telephonyExtraState, quote(incomingNumber), hasNumberExtra);
extraLogging(intent); // TODO: make optional or remove

View File

@@ -20,6 +20,7 @@ import dummydomain.yetanothercallblocker.event.CallOngoingEvent;
import dummydomain.yetanothercallblocker.utils.PhoneUtils;
import static dummydomain.yetanothercallblocker.EventUtils.postEvent;
import static dummydomain.yetanothercallblocker.utils.StringUtils.quote;
public class PhoneStateHandler {
@@ -51,7 +52,7 @@ public class PhoneStateHandler {
}
public void onRinging(Source source, String phoneNumber) {
LOG.debug("onRinging({}, \"{}\")", source, phoneNumber);
LOG.debug("onRinging({}, {})", source, quote(phoneNumber));
boolean ignore = false;
@@ -117,7 +118,7 @@ public class PhoneStateHandler {
}
public void onOffHook(Source source, String phoneNumber) {
LOG.debug("onOffHook({}, \"{}\")", source, phoneNumber);
LOG.debug("onOffHook({}, {})", source, quote(phoneNumber));
isOffHook = true;
@@ -125,7 +126,7 @@ public class PhoneStateHandler {
}
public void onIdle(Source source, String phoneNumber) {
LOG.debug("onIdle({}, \"{}\")", source, phoneNumber);
LOG.debug("onIdle({}, {})", source, quote(phoneNumber));
isOffHook = false;

View File

@@ -0,0 +1,9 @@
package dummydomain.yetanothercallblocker.utils;
public class StringUtils {
public static String quote(String s) {
return s == null ? null : '"' + s + '"';
}
}