Skip to content

Commit e6fbe2c

Browse files
author
Rafał Kuć
authored
Merge pull request #23 from sematext/allow_stopping_logs_sending
Allow stopping logs sending
2 parents 764e3b3 + 0b5d70c commit e6fbe2c

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ try {
124124

125125
Note that these meta fields are global, and will be attached to every event sent to Sematext.
126126

127+
Pausing & Resuming Logs Sending
128+
-------------------------------
129+
130+
The library can be instructed to stop sending logs on demand. To do that you need to call the following function:
131+
132+
```java
133+
logsene.pause();
134+
```
135+
136+
Logs sending can be resumed by calling the following function:
137+
138+
```java
139+
logsene.resume();
140+
```
141+
142+
Note that the logs that are in the buffer and were waiting to be sent at the time of pausing will not be sent until the logs sending process is resumed.
143+
127144

128145
Centralized Logging
129146
-------------------

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion 19
88
targetSdkVersion 28
99
versionCode 1
10-
versionName "2.2.1"
10+
versionName "2.2.2"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Apr 21 16:22:48 CEST 2020
1+
#Wed Jun 03 17:02:22 CEST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

logseneandroid/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 19
1010
targetSdkVersion 28
1111
versionCode 4
12-
versionName "2.2.1"
12+
versionName "2.2.2"
1313

1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1515

logseneandroid/src/main/java/com/sematext/logseneandroid/Logsene.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class Logsene {
8383
private boolean sendRequiresUnmeteredNetwork;
8484
private boolean sendRequiresDeviceIdle;
8585
private boolean sendRequiresBatteryNotLow;
86+
private boolean isActive;
8687
private LogseneLocationListener locationListener;
8788

8889
public Logsene(Context context) {
@@ -99,6 +100,7 @@ public Logsene(Context context, boolean automaticLocationEnabled) {
99100
if (automaticLocationEnabled) {
100101
this.locationListener = new LogseneLocationListener(context);
101102
}
103+
this.isActive = true;
102104
schedulePeriodicWorker();
103105
}
104106

@@ -150,6 +152,14 @@ private void config() {
150152
sendRequiresUnmeteredNetwork, sendRequiresDeviceIdle, sendRequiresBatteryNotLow));
151153
}
152154

155+
public void pause() {
156+
this.isActive = false;
157+
}
158+
159+
public void resume() {
160+
this.isActive = true;
161+
}
162+
153163
/**
154164
* Logs a simple message.
155165
*
@@ -426,7 +436,7 @@ private void addToQueue(JSONObject obj) {
426436
}
427437

428438
boolean canSend = lastScheduled == -1 || SystemClock.elapsedRealtime() - lastScheduled > minTimeDelay;
429-
if (preflightQueue.size() >= DEFAULT_MIN_BATCH_SIZE && canSend) {
439+
if (preflightQueue.size() >= DEFAULT_MIN_BATCH_SIZE && canSend && isActive) {
430440
scheduleConstrainedWorker();
431441
lastScheduled = SystemClock.elapsedRealtime();
432442
}

0 commit comments

Comments
 (0)