Include .aar Library Module Logs Into Android Application File Logger?
Is it possible to access log messages from 3rd party library aar modules somehow and append them when writing a customized file logger? My purpose with the file logger is to be abl
Solution 1:
Why don't you use the logcat
command to retrieve logs ?
Here is an example to send logs by email
publicstaticvoidsendLog(Context context) {
try {
StringfileName="logcat_" + System.currentTimeMillis() + ".txt";
FileoutputFile=newFile(context.getExternalCacheDir(), fileName);
@SuppressWarnings("unused")Processprocess= Runtime.getRuntime().exec("logcat -v time -f " + outputFile.getAbsolutePath());
IntentemailIntent=newIntent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Android Log");
emailIntent.putExtra(Intent.EXTRA_TEXT, "See attached log file");
emailIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, "com.yourapplicationid.fileprovider", outputFile));
context.startActivity(Intent.createChooser(emailIntent , "Send email..."));
} catch (Exception e) {
Log.e(TAG, "Exception when sending log: " + e.getMessage());
}
}
You need to specify a FileProvider
in your Manifest :
<providerandroid:name="android.support.v4.content.FileProvider"android:authorities="com.yourapplicationid.fileprovider"android:enabled="true"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_paths" /></provider>
And the XML file path
<paths><external-cache-pathname="external_cache"path="." /></paths>
More information here : https://developer.android.com/studio/command-line/logcat
Post a Comment for "Include .aar Library Module Logs Into Android Application File Logger?"