Kkk.
Kkk.

Reputation: 1

Java android get logs in file

This is how I get a logs from application :

try {
            SimpleDateFormat sdf = new SimpleDateFormat(
                    "yyyy-MM-dd", Locale.US);
            String currentDateandTime = sdf.format(new Date());
            final File path = new File(Environment.getExternalStorageDirectory(), "SMOK_komunal");
            if (!path.exists()) {
                path.mkdir();
            }
            Log.e("path ", path.getAbsolutePath());
            Runtime.getRuntime().exec("logcat  -f " + path + File.separator + "dbo_logcat_" + currentDateandTime + ".txt");
        } catch (IOException e) {
            e.printStackTrace();
        }

But in this logs I don't have a a date and time in lines how I can add date and time ?

Upvotes: 0

Views: 56

Answers (1)

Vishal Vaishnav
Vishal Vaishnav

Reputation: 3422

For getting date and time print log like this:

 Log.e("path ", path.getAbsolutePath()+ " and "+currentDateandTime );

It will give both file path and date and time

Upvotes: 1

Related Questions