Utility logger library for storing logs into database and push them to remote server for debugging
Utility logger library for storing logs into database and push them to remote server for debugging
A utility logger library for Android on top of standard Android Log class for debugging purpose. This is a simple library that will allow Android apps or library to store log into database so that developer can pull the logs from the database into File or push the logs to your remote server for debugging purpose. Want to know more on this and wondering why you should prefer using this library over doing it yourself. Check out the blog post or sample apk.
timeStamp + " | " + appVersion + " : " + osVersion + " | " + deviceUUID + " | [" + logLevelName + "]: " + message2017-10-05T14:46:36.541Z 1.0 | 0.0.1 : Android-7.1.1 | 62bb1162466c3eed | [INFO]: Log has been pushedDownload the latest version or grab via Gradle.
The library is available on mavenCentral() and jcenter(). In your module's build.gradle, add the following code snippet and run the gradle-sync.
from rest_framework import views
class SDKLogFileAPIView(views.APIView): ''' SDK Log endpoint for file uploads
Example curl call:
curl -i -X POST
-H "Content-Type: multipart/form-data"
-H "Authorization: token pk_e6c9cf663714fb4b96c12d265df554349e0db79b"
-H "Content-Disposition: attachment; filename=upload.txt"
-F "data=@/Users/Arjun/Desktop/filename.txt"
localhost:8000/api/v1/logs/
'''
parser_classes = (
parsers.FileUploadParser,
)
def post(self, request):dependencies {
...
compile 'com.hypertrack:hyperlog:0.0.10'
...
}Don't forget to add also the following dependencies
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.code.gson:gson:2.8.1'
and the following permession to AndroidManifest.xml
Inside onCreate of Application class or Launcher Activity.
HyperLog.initialize(this);
HyperLog.setLogLevel(Log.VERBOSE);HyperLog.d(TAG,"Debug Log");File file = HyperLog.getDeviceLogsInFile(this);Logs file can be pushed to your remote server or RequestBin(for testing) or to Logstash.
Steps:
HyperLog.setURL before calling HyperLog.pushLogs method otherwise exception will be thrown. Developers can also set a testing endpoint using RequestBin.HyperLog.setURL("API URL");HyperLog.pushLogs(this, false, new HLCallback() {
@Override
public void onSuccess(@NonNull Object response) {
}
@Override
public void onError(@NonNull VolleyError HLErrorResponse) {
}
});RequestBinRequestBin site and create a RequestBin.HyperLog.setURL.HyperLog.pushLogs to push the logs file to given endpoint. This is asynchronous call.HyperLog.pushLogs success, reload the requestbin page to view exactly which requests were made, what headers were sent, and raw body and so on, all in a pretty graphical setting like below image.RequestBin create your own endpoint on your server and start receiving logs on to your server for debugging.Logstash (part of ELK stack). We have discussed ELK in one of our blog.Request Bin Sample Response
The example code below will set you up with a view that can handle uploaded log files, decompress gzip, and print the contents of the file.
…Note:
HyperLog.pushLogs(Context mContext, boolean compress, HyperLogCallback callback);GZIP encoding.5000 logs.Default Log Message that will store in database.
timeStamp + " | " + appVersion + " : " + osVersion + " | " + deviceUUID + " | [" + logLevelName + "]: " + message2017-10-05T14:46:36.541Z 1.0 | 0.0.1 : Android-7.1.1 | 62bb1162466c3eed | [INFO]: Log has been pushedThis message can easily be customize.
LogFormat.getFormattedLogMessage method.class CustomLogMessageFormat extends LogFormat {
CustomLog(Context context) {
super(context);
}
public String getFormattedLogMessage(String logLevelName, String message, String timeStamp,
String senderName, String osVersion, String deviceUUID) {
//Custom Log Message Format
String formattedMessage = timeStamp + " : " + logLevelName + " : " + deviceUUID + " : " + message;
return formattedMessage;
}
}
Custom Log Message Format example
2017-10-05T14:46:36.541Z 1.0 | INFO | 62bb1162466c3eed | Log has been pushed
HyperLog or can be set later.HyperLog.initialize(this,new CustomLogMessageFormat(this));
OR
HyperLog.initialize(this);
HyperLog.setLogFormat(new CustomLogMessageFormat(this));HyperLog.d(TAG,"debug");
HyperLog.i(TAG,"information");
HyperLog.e(TAG,"error");
HyperLog.v(TAG,"verbose");
HyperLog.w(TAG,"warning");
HyperLog.a(TAG,"assert");
HyperLog.exception(TAG,"exception",throwable);HyperLog.hasPendingDeviceLogs();HyperLog.logCount();HashMap additionalHeaders = new HashMap<>();
additionalHeaders.put("Authorization","Token");
HyperLog.pushLogs(this, additionalHeaders, false, HLCallback);expiryTimeInSeconds.HyperLog.initialize(@NonNull Context context, int expiryTimeInSeconds);DeviceLog model or list of String .By default, fetched logs will delete from the database. Developers can override to change the default functionality.HyperLog.getDeviceLogs(boolean deleteLogs);
HyperLog.getDeviceLogsInFile(Context mContext, boolean deleteLogs);HyperLog.getDeviceLogs(boolean deleteLogs, int batchNo);HyperLog.getDeviceLogBatchCount.HyperLog.deleteLogs.Read the different methods and how to implement HyperLogs in Android using Kotlin here.
Please use the issues tracker to raise bug reports and feature requests. We'd love to see your pull requests, so send them in!
Developers use HyperTrack to build location features, not infrastructure. We reduce the complexity of building and operating location features to a few APIs that just work. Sign up and start building! Join our Slack community to connect with other developers building location features. Email us at [email protected] if you need any help.
…No open issues yet, or sync has not completed.