Skip to content

Commit

Permalink
Option to filter logs by priority.
Browse files Browse the repository at this point in the history
This change improves performance, as with disabled logs the byte arrays are not converted to String just for logging purposes.
  • Loading branch information
philips77 committed Jan 27, 2022
1 parent 4318607 commit 48930ab
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 174 deletions.
16 changes: 14 additions & 2 deletions ble/src/main/java/no/nordicsemi/android/ble/BleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import androidx.annotation.StringRes;
import no.nordicsemi.android.ble.annotation.ConnectionPriority;
import no.nordicsemi.android.ble.annotation.ConnectionState;
import no.nordicsemi.android.ble.annotation.LogPriority;
import no.nordicsemi.android.ble.annotation.PairingVariant;
import no.nordicsemi.android.ble.annotation.PhyMask;
import no.nordicsemi.android.ble.annotation.PhyOption;
Expand Down Expand Up @@ -372,7 +373,18 @@ public final int getBatteryValue() {
}

@Override
public void log(final int priority, @NonNull final String message) {
@LogPriority
public int getMinLogPriority() {
// By default, the library will log entries on INFO and higher priorities.
// Consider changing to false in production to increase speed and decrease memory allocations.

// Note: Before version 2.4.0 all logs were logged by default, so this changes previous behavior.
// To restore it, return Log.VERBOSE here.
return Log.INFO;
}

@Override
public void log(@LogPriority final int priority, @NonNull final String message) {
// Override to log events. Simple log can use Logcat:
//
// Log.println(priority, TAG, message);
Expand All @@ -390,7 +402,7 @@ public void log(final int priority, @NonNull final String message) {
}

@Override
public void log(final int priority, @StringRes final int messageRes,
public void log(@LogPriority final int priority, @StringRes final int messageRes,
@Nullable final Object... params) {
final String message = context.getString(messageRes, params);
log(priority, message);
Expand Down

0 comments on commit 48930ab

Please sign in to comment.