Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit 50ee3f5

Browse files
authored
[RQLY-158] feat: logs support (#16)
1 parent d1e3fff commit 50ee3f5

36 files changed

+2096
-10
lines changed

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ POM_URL=https://github.com/requestly/requestly-android-sdk
3030
POM_SCM_CONNECTION=scm:git:git://github.com/requestly/requestly-android-sdk.git
3131
POM_LICENSE_NAME=The Apache Software License, Version 2.0
3232
POM_LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
33+
34+
android.enableJetifier=true

requestly-android-core/src/main/java/io/requestly/android/core/Requestly.kt

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@ import android.app.Application
44
import android.content.Context
55
import android.util.Log
66
import io.requestly.android.core.internal.support.ListNotificationHelper
7+
import io.requestly.android.core.modules.logs.lib.lynx.main.LynxConfig
8+
import io.requestly.android.core.modules.logs.lib.lynx.main.model.*
9+
import io.requestly.android.core.modules.logs.lib.lynx.main.presenter.LynxRequestlyPresenter
710

811
class Requestly {
912
companion object {
1013
private lateinit var INSTANCE: Requestly
1114

12-
fun getInstance(): Requestly? {
15+
@JvmStatic
16+
fun getInstance(): Requestly {
1317
return INSTANCE
1418
}
1519
}
1620

1721
lateinit var applicationContext: Context
1822
lateinit var listNotificationHelper: ListNotificationHelper
1923

24+
// Logs Helpers
25+
var logsConfig: LynxConfig = LynxConfig()
26+
lateinit var logsLynx: Lynx
27+
lateinit var logsLynxPresenter: LynxRequestlyPresenter
28+
2029
class Builder(
2130
private val application: Application,
2231
private val appToken: String,
@@ -25,20 +34,41 @@ class Requestly {
2534

2635
// Start Configuration: Different Configurations of Builder
2736
private var networkLoggerUIState = true
37+
38+
// module/logs
39+
private var logsConfig = LynxConfig()
40+
2841
// End Configuration
2942

3043
fun build() {
3144
Log.d("RQ-Core", "Start: Building Core")
32-
Requestly.INSTANCE = Requestly()
33-
Requestly.getInstance()?.applicationContext = applicationContext
34-
Requestly.getInstance()?.listNotificationHelper = ListNotificationHelper(applicationContext)
45+
INSTANCE = Requestly()
46+
getInstance()?.applicationContext = applicationContext
47+
getInstance()?.listNotificationHelper = ListNotificationHelper(applicationContext)
3548

3649
SettingsManager.getInstance().setAppToken(appToken)
3750
KeyValueStorageManager.initialize(applicationContext)
3851
this.updateFeaturesState()
52+
53+
buildLogsModule()
3954
Log.d("RQ-Core", "Finish: Building Core")
4055
}
4156

57+
// TODO: @wrongSahil
58+
fun buildLogsModule() {
59+
// LynxConfig init
60+
// Lynx init
61+
// LynxRequestlyPresenter init
62+
val lynx = Lynx(Logcat(), AndroidMainThread(), TimeProvider())
63+
lynx.config = logsConfig
64+
val presenter = LynxRequestlyPresenter(lynx, logsConfig.maxNumberOfTracesToShow)
65+
presenter.resume()
66+
67+
getInstance().logsConfig = logsConfig
68+
getInstance().logsLynx = lynx
69+
getInstance().logsLynxPresenter = presenter
70+
}
71+
4272
private fun updateFeaturesState() {
4373
Log.d("RQ-Core", "Start: Updating Features")
4474
SettingsManager.getInstance().setFeatureState(Feature.NETWORK_LOGGER_UI, this.networkLoggerUIState)
@@ -49,5 +79,20 @@ class Requestly {
4979
this.networkLoggerUIState = visible
5080
return this
5181
}
82+
83+
fun setLoggerConfig(
84+
maxNumberOfTracesToShow: Int = 2500,
85+
filter: String? = null,
86+
filterTraceLevel: TraceLevel? = null,
87+
textSizeInPx: Float = 36F,
88+
samplingRate: Int = 150): Builder
89+
{
90+
logsConfig.maxNumberOfTracesToShow = maxNumberOfTracesToShow
91+
logsConfig.filter = filter
92+
logsConfig.filterTraceLevel = filterTraceLevel
93+
logsConfig.textSizeInPx = textSizeInPx
94+
logsConfig.samplingRate = samplingRate
95+
return this
96+
}
5297
}
5398
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* Copyright (C) 2015 Pedro Vicente Gomez Sanchez.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.requestly.android.core.modules.logs.lib.lynx.main;
18+
19+
import java.io.Serializable;
20+
21+
import io.requestly.android.core.modules.logs.lib.lynx.main.model.TraceLevel;
22+
23+
/**
24+
* Lynx configuration parameters used to open main activity. All the configuration library is
25+
* provided by library clients using this class. With LynxConfig you can privde different values
26+
* for:
27+
*
28+
* - Max number of traces to show in LynxView.
29+
* - Filter used to get a list of traces to show.
30+
* - Text size in DP used to render a trace.
31+
* - Sampling rate used to read from the Logcat output.
32+
*
33+
* @author Pedro Vicente Gomez Sanchez.
34+
*/
35+
public class LynxConfig implements Serializable, Cloneable {
36+
private static final long serialVersionUID = 293939299388293L;
37+
38+
private static final float DEFAULT_TEXT_SIZE_IN_PX = 36;
39+
40+
private int maxNumberOfTracesToShow = 2500;
41+
private String filter;
42+
private TraceLevel filterTraceLevel;
43+
private Float textSizeInPx;
44+
private int samplingRate = 150;
45+
46+
public LynxConfig() {
47+
filter = "";
48+
filterTraceLevel = TraceLevel.VERBOSE;
49+
}
50+
51+
public LynxConfig setMaxNumberOfTracesToShow(int maxNumberOfTracesToShow) {
52+
if (maxNumberOfTracesToShow <= 0) {
53+
throw new IllegalArgumentException(
54+
"You can't use a max number of traces equals or lower than zero.");
55+
}
56+
57+
this.maxNumberOfTracesToShow = maxNumberOfTracesToShow;
58+
return this;
59+
}
60+
61+
public LynxConfig setFilter(String filter) {
62+
if (filter == null) {
63+
throw new IllegalArgumentException("filter can't be null");
64+
}
65+
this.filter = filter;
66+
return this;
67+
}
68+
69+
public LynxConfig setFilterTraceLevel(TraceLevel filterTraceLevel) {
70+
if (filterTraceLevel == null) {
71+
throw new IllegalArgumentException("filterTraceLevel can't be null");
72+
}
73+
this.filterTraceLevel = filterTraceLevel;
74+
return this;
75+
}
76+
77+
public LynxConfig setTextSizeInPx(float textSizeInPx) {
78+
this.textSizeInPx = textSizeInPx;
79+
return this;
80+
}
81+
82+
public LynxConfig setSamplingRate(int samplingRate) {
83+
this.samplingRate = samplingRate;
84+
return this;
85+
}
86+
87+
public int getMaxNumberOfTracesToShow() {
88+
return maxNumberOfTracesToShow;
89+
}
90+
91+
public String getFilter() {
92+
return filter;
93+
}
94+
95+
public TraceLevel getFilterTraceLevel() {
96+
return filterTraceLevel;
97+
}
98+
99+
public boolean hasFilter() {
100+
return !"".equals(filter) || !TraceLevel.VERBOSE.equals(filterTraceLevel);
101+
}
102+
103+
public float getTextSizeInPx() {
104+
return textSizeInPx == null ? DEFAULT_TEXT_SIZE_IN_PX : textSizeInPx;
105+
}
106+
107+
public boolean hasTextSizeInPx() {
108+
return textSizeInPx != null;
109+
}
110+
111+
public int getSamplingRate() {
112+
return samplingRate;
113+
}
114+
115+
@Override public boolean equals(Object o) {
116+
if (this == o) return true;
117+
if (!(o instanceof LynxConfig)) return false;
118+
119+
LynxConfig that = (LynxConfig) o;
120+
121+
if (maxNumberOfTracesToShow != that.maxNumberOfTracesToShow) return false;
122+
if (samplingRate != that.samplingRate) return false;
123+
if (filter != null ? !filter.equals(that.filter) : that.filter != null) return false;
124+
if (textSizeInPx != null ? !textSizeInPx.equals(that.textSizeInPx)
125+
: that.textSizeInPx != null) {
126+
return false;
127+
}
128+
if (filterTraceLevel != that.filterTraceLevel) return false;
129+
return true;
130+
}
131+
132+
@Override public int hashCode() {
133+
int result = maxNumberOfTracesToShow;
134+
result = 31 * result + (filter != null ? filter.hashCode() : 0);
135+
result = 31 * result + (textSizeInPx != null ? textSizeInPx.hashCode() : 0);
136+
result = 31 * result + samplingRate;
137+
return result;
138+
}
139+
140+
@Override public Object clone() {
141+
return new LynxConfig().setMaxNumberOfTracesToShow(getMaxNumberOfTracesToShow())
142+
.setFilter(filter)
143+
.setFilterTraceLevel(filterTraceLevel)
144+
.setSamplingRate(getSamplingRate());
145+
}
146+
147+
@Override public String toString() {
148+
return "LynxConfig{"
149+
+ "maxNumberOfTracesToShow="
150+
+ maxNumberOfTracesToShow
151+
+ ", filter='"
152+
+ filter
153+
+ '\''
154+
+ ", textSizeInPx="
155+
+ textSizeInPx
156+
+ ", samplingRate="
157+
+ samplingRate
158+
+ '}';
159+
}
160+
}

0 commit comments

Comments
 (0)