Skip to content

Commit 03902b8

Browse files
committed
Fix log collector and app name
1 parent f91bdfc commit 03902b8

8 files changed

Lines changed: 98 additions & 96 deletions

File tree

android/app/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ def getGitHash = { ->
1717
android {
1818
compileSdk 33
1919

20-
buildToolsVersion "32.0.0"
21-
2220
defaultConfig {
2321
applicationId "com.httpsms"
2422
minSdk 26
2523
targetSdk 33
2624
versionCode 1
2725
versionName "${getGitHash()}"
28-
2926
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3027
}
3128

@@ -55,7 +52,7 @@ dependencies {
5552
implementation 'com.google.firebase:firebase-messaging-ktx'
5653
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
5754
implementation 'com.jakewharton.timber:timber:5.0.1'
58-
implementation 'androidx.preference:preference:1.2.0'
55+
implementation 'androidx.preference:preference:1.2.1'
5956
implementation 'androidx.work:work-runtime-ktx:2.7.1'
6057
implementation 'androidx.core:core-ktx:1.9.0'
6158
implementation "androidx.cardview:cardview:1.0.0"

android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
109109

110110
if (BuildConfig.DEBUG) {
111111
Timber.plant(Timber.DebugTree())
112-
Timber.plant(LogtailTree(this.applicationContext))
112+
Timber.plant(LogzTree(this.applicationContext))
113113
}
114114
}
115115

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,89 @@
1-
package com.httpsms
2-
3-
import android.content.Context
4-
import android.os.Build
5-
import com.beust.klaxon.Klaxon
6-
import okhttp3.MediaType.Companion.toMediaType
7-
import okhttp3.OkHttpClient
8-
import okhttp3.Request
9-
import okhttp3.RequestBody.Companion.toRequestBody
10-
import timber.log.Timber
11-
import java.time.ZoneOffset
12-
import java.time.ZonedDateTime
13-
import java.time.format.DateTimeFormatter
14-
import java.util.concurrent.ConcurrentLinkedQueue
15-
16-
class LogtailTree(val context: Context): Timber.DebugTree() {
17-
private val client = OkHttpClient()
18-
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
19-
private val queue: ConcurrentLinkedQueue<LogEntry> = ConcurrentLinkedQueue<LogEntry>()
20-
21-
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
22-
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
23-
val logEntry = LogEntry(
24-
BuildConfig.VERSION_NAME,
25-
priority,
26-
severity(priority),
27-
tag,
28-
message,
29-
Build.MODEL,
30-
Build.BRAND,
31-
Build.DEVICE,
32-
Build.VERSION.SDK_INT,
33-
ZonedDateTime.now(ZoneOffset.UTC).format(formatter),
34-
Settings.getUserID(context),
35-
t
36-
)
37-
queue.add(logEntry)
38-
if (queue.size < 100) {
39-
return
40-
}
41-
42-
val logEntries = queue.toArray()
43-
queue.clear()
44-
45-
val request: Request = Request.Builder()
46-
.url("https://in.logtail.com")
47-
.post(Klaxon().toJsonString(logEntries).toRequestBody(jsonMediaType))
48-
.header("Authorization", "Bearer m7ZoA8u5KRYNe6RnEdWeZqsZ")
49-
.build()
50-
51-
Thread {
52-
try {
53-
val response = client.newCall(request).execute()
54-
response.body?.close()
55-
} catch(_: Exception) {
56-
}
57-
}.start()
58-
}
59-
60-
private fun severity(priority: Int): String {
61-
return when(priority) {
62-
3 -> "DEBUG"
63-
4 -> "INFO"
64-
5 -> "WARNING"
65-
6 -> "ERROR"
66-
7 -> "ASSERT"
67-
else -> "VERBOSE"
68-
}
69-
}
70-
71-
class LogEntry(
72-
val release: String,
73-
val priority: Int,
74-
val severity: String,
75-
val tag: String?,
76-
val message: String,
77-
val model: String,
78-
val brand: String,
79-
val device: String,
80-
val version: Int,
81-
val dt: String,
82-
val userID: String,
83-
val throwable: Throwable?)
84-
}
1+
package com.httpsms
2+
3+
import android.content.Context
4+
import android.os.Build
5+
import com.beust.klaxon.Json
6+
import com.beust.klaxon.Klaxon
7+
import okhttp3.MediaType.Companion.toMediaType
8+
import okhttp3.OkHttpClient
9+
import okhttp3.Request
10+
import okhttp3.RequestBody.Companion.toRequestBody
11+
import timber.log.Timber
12+
import java.time.ZoneOffset
13+
import java.time.ZonedDateTime
14+
import java.time.format.DateTimeFormatter
15+
import java.util.concurrent.ConcurrentLinkedQueue
16+
17+
class LogzTree(val context: Context): Timber.DebugTree() {
18+
private val client = OkHttpClient()
19+
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
20+
private val queue: ConcurrentLinkedQueue<LogEntry> = ConcurrentLinkedQueue<LogEntry>()
21+
22+
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
23+
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
24+
val logEntry = LogEntry(
25+
BuildConfig.VERSION_NAME,
26+
priority,
27+
severity(priority),
28+
tag,
29+
message,
30+
Build.MODEL,
31+
Build.BRAND,
32+
Build.DEVICE,
33+
Build.VERSION.SDK_INT,
34+
ZonedDateTime.now(ZoneOffset.UTC).format(formatter),
35+
Settings.getUserID(context),
36+
t
37+
)
38+
queue.add(logEntry)
39+
if (queue.size < 100) {
40+
return
41+
}
42+
43+
val logEntries = queue.toArray()
44+
queue.clear()
45+
46+
val body = logEntries.joinToString(separator = "\n") { x -> Klaxon().toJsonString(x) }
47+
.toRequestBody("application/x-www-form-urlencoded".toMediaType())
48+
49+
val request: Request = Request.Builder()
50+
.url("https://listener.logz.io:8071?token=cTCUVJoTDrPjaFcanAPRzIsYyThyrIDw&type=http-bulk")
51+
.post(body)
52+
.header("Content-Type", "application/x-www-form-urlencoded")
53+
.build()
54+
55+
Thread {
56+
try {
57+
val response = client.newCall(request).execute()
58+
response.body?.close()
59+
} catch(ex: Exception) {
60+
}
61+
}.start()
62+
}
63+
64+
private fun severity(priority: Int): String {
65+
return when(priority) {
66+
3 -> "DEBUG"
67+
4 -> "INFO"
68+
5 -> "WARNING"
69+
6 -> "ERROR"
70+
7 -> "ASSERT"
71+
else -> "VERBOSE"
72+
}
73+
}
74+
75+
class LogEntry(
76+
val release: String,
77+
val priority: Int,
78+
val severity: String,
79+
val tag: String?,
80+
val message: String,
81+
val model: String,
82+
val brand: String,
83+
val device: String,
84+
val version: Int,
85+
@Json(name = "@timestamp")
86+
val dt: String,
87+
val userID: String,
88+
val throwable: Throwable?)
89+
}

android/app/src/main/java/com/httpsms/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class MainActivity : AppCompatActivity() {
216216

217217
if (BuildConfig.DEBUG) {
218218
Timber.plant(Timber.DebugTree())
219-
Timber.plant(LogtailTree(this.applicationContext))
219+
Timber.plant(LogzTree(this.applicationContext))
220220
}
221221
}
222222

android/app/src/main/java/com/httpsms/SettingsActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SettingsActivity : AppCompatActivity() {
8282
Timber.d("logout button clicked")
8383
MaterialAlertDialogBuilder(this)
8484
.setTitle("Confirm")
85-
.setMessage("Are you sure you want to logout of the Http SMS App?")
85+
.setMessage("Are you sure you want to logout of the httpSMS App?")
8686
.setNeutralButton("Cancel"){ _, _ -> Timber.d("logout dialog canceled") }
8787
.setPositiveButton("Logout"){_, _ ->
8888
Timber.d("logging out user")

android/app/src/main/java/com/httpsms/services/StickyNotificationService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class StickyNotificationService: Service() {
6868
)
6969

7070
return builder
71-
.setContentTitle("SMS Listener")
72-
.setContentText("HTTP SMS is listening for sent and received SMS messages in the background.")
71+
.setContentTitle("httpSMS Listener")
72+
.setContentText("httpSMS is listening for sent and received SMS messages in the background.")
7373
.setContentIntent(pendingIntent)
7474
.setOngoing(true)
7575
.setSmallIcon(R.drawable.ic_stat_name)

android/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
2-
<string name="app_name">HTTP SMS</string>
2+
<string name="app_name">httpSMS</string>
33
<string name="nextRefreshTime">23/06/2022 18:58:30</string>
44
<string name="menuIconDescription">Menu Icon</string>
55
<string name="menuIconName">More</string>

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ buildscript {
1212
}
1313

1414
plugins {
15-
id 'com.android.application' version '8.0.2' apply false
16-
id 'com.android.library' version '8.0.2' apply false
15+
id 'com.android.application' version '8.1.0' apply false
16+
id 'com.android.library' version '8.1.0' apply false
1717
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
1818
}
1919

0 commit comments

Comments
 (0)