Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit ec20d8a

Browse files
committed
Remove internal logs, handle possible init exception
1 parent ed2b6d3 commit ec20d8a

File tree

7 files changed

+17
-53
lines changed

7 files changed

+17
-53
lines changed

hyperlog/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Mon Mar 01 12:21:49 KGT 2021
1+
#Mon Mar 01 16:27:19 KGT 2021
22
version=0.0.10
3-
VERSION_BUILD=435
3+
VERSION_BUILD=436
44
VERSION_PATCH=10

hyperlog/src/main/java/com/hypertrack/hyperlog/DeviceLogDatabaseHelper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ of this software and associated documentation files (the "Software"), to deal
2727
import android.content.Context;
2828
import android.database.sqlite.SQLiteDatabase;
2929
import android.database.sqlite.SQLiteOpenHelper;
30-
import android.util.Log;
3130

3231
import java.util.List;
3332

@@ -36,7 +35,6 @@ of this software and associated documentation files (the "Software"), to deal
3635
*/
3736
class DeviceLogDatabaseHelper extends SQLiteOpenHelper implements DeviceLogDataSource {
3837

39-
private static final String TAG = DeviceLogDatabaseHelper.class.getSimpleName();
4038
private static final String DATABASE_NAME = "com.hypertrack.common.device_logs.db";
4139
private static final int DATABASE_VERSION = 2;
4240

@@ -50,7 +48,11 @@ private DeviceLogDatabaseHelper(Context context) {
5048

5149
private void initializeDatabase() {
5250
if (database == null)
53-
database = this.getWritableDatabase();
51+
try {
52+
database = this.getWritableDatabase();
53+
} catch (Exception e) {
54+
database = null;
55+
}
5456
}
5557

5658
static DeviceLogDatabaseHelper getInstance(Context context) {
@@ -66,13 +68,11 @@ static DeviceLogDatabaseHelper getInstance(Context context) {
6668
@Override
6769
public void onCreate(SQLiteDatabase db) {
6870
DeviceLogTable.onCreate(db);
69-
Log.d(TAG, "DeviceLogDatabaseHelper onCreate called.");
7071
}
7172

7273
@Override
7374
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
7475
DeviceLogTable.onUpgrade(db, oldVersion, newVersion);
75-
Log.d(TAG, "DeviceLogDatabaseHelper onUpgrade called.");
7676
}
7777

7878
@Override

hyperlog/src/main/java/com/hypertrack/hyperlog/DeviceLogTable.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ of this software and associated documentation files (the "Software"), to deal
4242

4343
class DeviceLogTable {
4444

45-
private static final String TAG = DeviceLogTable.class.getSimpleName();
46-
private static final int DEVICE_LOG_REQUEST_QUERY_LIMIT = 5000;
45+
private static final int DEVICE_LOG_REQUEST_QUERY_LIMIT = 10000;
4746

4847
private static final String TABLE_NAME = "device_logs";
4948
private static final String COLUMN_ID = "_id";
@@ -65,7 +64,6 @@ static void onCreate(SQLiteDatabase db) {
6564
db.execSQL(DATABASE_CREATE);
6665
} catch (Exception e) {
6766
e.printStackTrace();
68-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while onCreate: " + e);
6967
}
7068
}
7169

@@ -77,11 +75,8 @@ static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
7775
try {
7876
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
7977
onCreate(db);
80-
81-
HyperLog.i("HYPERLOG", "DeviceLogTable onUpgrade called. Executing drop_table query to clear old logs.");
8278
} catch (Exception e) {
8379
e.printStackTrace();
84-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while onUpgrade: " + e);
8580
}
8681
}
8782

@@ -94,7 +89,6 @@ static long getCount(SQLiteDatabase db) {
9489
return DatabaseUtils.queryNumEntries(db, TABLE_NAME);
9590
} catch (Exception e) {
9691
e.printStackTrace();
97-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while getCount: " + e);
9892
return 0L;
9993
}
10094
}
@@ -109,7 +103,6 @@ static int getDeviceLogBatchCount(SQLiteDatabase db) {
109103

110104
} catch (Exception e) {
111105
e.printStackTrace();
112-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while getDeviceLogBatchCount: " + e);
113106
return 0;
114107
}
115108
}
@@ -126,7 +119,6 @@ static void addDeviceLog(SQLiteDatabase db, String deviceLog) {
126119
db.insert(TABLE_NAME, null, contentValues);
127120
} catch (Exception e) {
128121
e.printStackTrace();
129-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while addDeviceLog: " + e);
130122
}
131123
}
132124

@@ -158,7 +150,6 @@ static void deleteDeviceLog(SQLiteDatabase db, List<DeviceLogModel> deviceLogLis
158150
db.delete(TABLE_NAME, whereClause, null);
159151
} catch (Exception e) {
160152
e.printStackTrace();
161-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while deleteDeviceLog: " + e);
162153
}
163154
}
164155

@@ -171,7 +162,6 @@ static void deleteAllDeviceLogs(SQLiteDatabase db) {
171162
db.delete(TABLE_NAME, null, null);
172163
} catch (Exception e) {
173164
e.printStackTrace();
174-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while deleteAllDeviceLogs: " + e);
175165
}
176166
}
177167

@@ -218,7 +208,6 @@ static List<DeviceLogModel> getDeviceLogs(SQLiteDatabase db, int batch) {
218208
}
219209
} catch (Exception e) {
220210
e.printStackTrace();
221-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while getDeviceLogs: " + e);
222211
} finally {
223212
cursor.close();
224213
}
@@ -242,7 +231,6 @@ public static void clearOldLogs(SQLiteDatabase db, int expiryTimeInSeconds) {
242231

243232
} catch (Exception e) {
244233
e.printStackTrace();
245-
HyperLog.e("HYPERLOG", "DeviceLogTable: Exception occurred while deleteAllDeviceLogs: " + e);
246234
}
247235
}
248236
}

hyperlog/src/main/java/com/hypertrack/hyperlog/HLHTTPMultiPartPostRequest.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ of this software and associated documentation files (the "Software"), to deal
5252

5353
class HLHTTPMultiPartPostRequest<T> extends Request<T> {
5454

55-
private static final String TAG = HLHTTPMultiPartPostRequest.class.getSimpleName();
5655
private final Gson mGson;
5756
private final Class<T> mResponseType;
5857
private final Response.Listener<T> mListener;
@@ -101,10 +100,8 @@ private byte[] getCompressed(byte[] requestBody) {
101100
return compressed;
102101

103102
} catch (Exception exception) {
104-
HyperLog.e("HYPERLOG", "Exception occurred while getCompressed: " + exception);
105103
mGzipEnabled = false;
106104
} catch (OutOfMemoryError error) {
107-
HyperLog.e("HYPERLOG", "OutOfMemory Error occurred while getCompressed: " + error);
108105
mGzipEnabled = false;
109106
}
110107
}
@@ -115,14 +112,12 @@ private byte[] getCompressed(byte[] requestBody) {
115112
private byte[] getRequestBody(byte[] requestBody) {
116113
byte[] compressedRequestBody = getCompressed(requestBody);
117114
if (mGzipEnabled) {
118-
HyperLog.i("HYPERLOG", "Compressed FileSize: " + compressedRequestBody.length + " Bytes");
119115
return compressedRequestBody;
120116
} else {
121117
try {
122-
HyperLog.i("HYPERLOG", "Compressed FileSize: " + requestBody.length + " Bytes");
123118
return requestBody;
124119
} catch (Exception exception) {
125-
HyperLog.e("HYPERLOG", "Exception occurred while getRequestBody: " + exception);
120+
exception.printStackTrace();
126121
}
127122
}
128123
return null;
@@ -151,7 +146,7 @@ public static String getDecompressed(byte[] compressed) throws IOException {
151146
is.close();
152147
return string.toString();
153148
} catch (Exception exception) {
154-
HyperLog.e("HYPERLOG", "Exception occurred while getDecompressed: " + exception);
149+
exception.printStackTrace();
155150
}
156151
return null;
157152
}
@@ -190,12 +185,8 @@ protected VolleyError parseNetworkError(VolleyError volleyError) {
190185
try {
191186
String json = new String(
192187
volleyError.networkResponse.data, HttpHeaderParser.parseCharset(volleyError.networkResponse.headers));
193-
194-
HyperLog.i("HYPERLOG", "Status Code: " + volleyError.networkResponse.statusCode +
195-
" Data: " + json);
196-
197188
} catch (Exception e) {
198-
HyperLog.e("HYPERLOG", "Exception occurred while HTTPPatchRequest parseNetworkError: " + e, e);
189+
e.printStackTrace();
199190
}
200191

201192
return super.parseNetworkError(volleyError);
@@ -219,7 +210,6 @@ protected Response<T> parseNetworkResponse(NetworkResponse response) {
219210

220211
@Override
221212
protected void deliverResponse(T response) {
222-
HyperLog.i("HYPERLOG", "deliverResponse: ");
223213
if (mListener != null)
224214
mListener.onResponse(response);
225215
}

hyperlog/src/main/java/com/hypertrack/hyperlog/HyperLog.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ of this software and associated documentation files (the "Software"), to deal
2424

2525
package com.hypertrack.hyperlog;
2626

27+
import android.annotation.SuppressLint;
2728
import android.content.Context;
2829
import androidx.annotation.NonNull;
2930
import android.text.TextUtils;
@@ -50,14 +51,14 @@ public class HyperLog {
5051

5152
private static final String TAG = "HyperLog";
5253
public static final String TAG_ASSERT = "ASSERT";
53-
public static final String TAG_HYPERLOG = "HYPERLOG";
5454

5555
private static int logLevel = Log.WARN;
5656

5757
private static DeviceLogList mDeviceLogList;
5858
private static String URL;
5959
private static final int EXPIRY_TIME = 7 * 24 * 60 * 60;// 7 Days
6060
private static LogFormat mLogFormat;
61+
@SuppressLint("StaticFieldLeak")
6162
private static Context context;
6263
private static ExecutorService executorService;
6364

@@ -110,7 +111,6 @@ public static void initialize(@NonNull Context context, int expiryTimeInSeconds,
110111
@NonNull LogFormat logFormat) {
111112

112113
if (context == null) {
113-
Log.e(TAG, "HyperLog isn't initialized: Context couldn't be null");
114114
return;
115115
}
116116

@@ -492,8 +492,6 @@ public static File getDeviceLogsInFile(Context mContext, String fileName, boolea
492492
if (file != null) {
493493
if (deleteLogs)
494494
mDeviceLogList.clearDeviceLogs(deviceLogList);
495-
HyperLog.i("HYPERLOG", "Log File has been created at " +
496-
file.getAbsolutePath());
497495
}
498496
}
499497
logsBatchCount--;
@@ -620,15 +618,12 @@ public static void pushLogs(Context mContext, String fileName, HashMap<String,
620618
return;
621619

622620
if (TextUtils.isEmpty(URL)) {
623-
HyperLog.e("HYPERLOG", "API endpoint URL is missing. Set URL using " +
624-
"HyperLog.setURL method");
625621
return;
626622
}
627623

628624
VolleyUtils.cancelPendingRequests(mContext, TAG);
629625

630626
if (TextUtils.isEmpty(URL)) {
631-
HyperLog.e("HYPERLOG", "URL is missing. Please set the URL to push the logs.");
632627
return;
633628
}
634629
if (!hasPendingDeviceLogs())
@@ -643,9 +638,6 @@ public static void pushLogs(Context mContext, String fileName, HashMap<String,
643638
while (logsBatchCount != 0) {
644639

645640
final List<DeviceLogModel> deviceLogs = getDeviceLogs(false, logsBatchCount);
646-
deviceLogs.add(new DeviceLogModel(getFormattedLog(Log.INFO, TAG_HYPERLOG,
647-
"Log Counts: " + deviceLogs.size() + " | File Size: " +
648-
deviceLogs.toString().length() + " bytes.")));
649641
//Get string data into byte format.
650642
byte[] bytes = Utils.getByteData(deviceLogs);
651643

@@ -660,7 +652,6 @@ public static void pushLogs(Context mContext, String fileName, HashMap<String,
660652
public void onResponse(Object response) {
661653
temp[0]--;
662654
mDeviceLogList.clearDeviceLogs(deviceLogs);
663-
HyperLog.i("HYPERLOG", "Log has been pushed");
664655

665656
if (callback != null && temp[0] == 0) {
666657
if (isAllLogsPushed[0]) {
@@ -679,8 +670,6 @@ public void onErrorResponse(VolleyError error) {
679670
isAllLogsPushed[0] = false;
680671
temp[0]--;
681672
error.printStackTrace();
682-
HyperLog.exception(TAG, "Error has occurred while pushing " +
683-
"logs: ", error);
684673

685674
if (temp[0] == 0) {
686675
if (callback != null) {

hyperlog/src/main/java/com/hypertrack/hyperlog/utils/HLDateTimeUtility.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ public static String getCurrentTime() {
5454
dateFormat.setTimeZone(TimeZone.getTimeZone(HT_TIMEZONE_UTC));
5555
currentTime = dateFormat.format(new Date());
5656
} catch (Exception e) {
57-
HyperLog.e("HYPERLOG", "Exception while getCurrentTime: " + e);
5857
currentTime = "";
5958
}
60-
return currentTime != null ? currentTime : "";
59+
return currentTime;
6160
}
6261

6362
public static String getFormattedTime(Date date) {
@@ -70,7 +69,7 @@ public static String getFormattedTime(Date date) {
7069
dateFormat.setTimeZone(TimeZone.getTimeZone(HT_TIMEZONE_UTC));
7170
return dateFormat.format(date);
7271
} catch (Exception e) {
73-
HyperLog.e("HYPERLOG", "Exception while getFormattedTime: " + e);
72+
e.printStackTrace();
7473
}
7574

7675
return getCurrentTime();
@@ -85,7 +84,7 @@ public static Date getFormattedDate(String time) {
8584
format.setTimeZone(TimeZone.getTimeZone(HT_TIMEZONE_UTC));
8685
return format.parse(time);
8786
} catch (Exception e) {
88-
HyperLog.e("HYPERLOG", "Exception while getFormattedDate: " + e);
87+
e.printStackTrace();
8988
}
9089

9190
return new Date();

hyperlog/src/main/java/com/hypertrack/hyperlog/utils/Utils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@ public static File writeStringsToFile(Context context, List<String> data, String
5858
String dirPath = context.getExternalFilesDir(null).getAbsolutePath() + "/LogFiles";
5959

6060
if (TextUtils.isEmpty(dirPath)) {
61-
HyperLog.e("HYPERLOG", "Error occurred while getting directory");
6261
return null;
6362
}
6463

6564
//Create a directory if doesn't exist.
6665
File filePath = new File(dirPath);
6766
if (!filePath.exists()) {
6867
if (!filePath.mkdirs()) {
69-
HyperLog.e("HYPERLOG", "Error occurred while creating file.");
7068
return null;
7169
}
7270
}
@@ -79,7 +77,7 @@ public static File writeStringsToFile(Context context, List<String> data, String
7977
return logFile;
8078

8179
} catch (Exception e) {
82-
HyperLog.exception(TAG, e);
80+
e.printStackTrace();
8381
}
8482
return null;
8583
}

0 commit comments

Comments
 (0)