0

I am a little bit novice in android. I actually want to write the information that is shown in the logcat into an xml file that will be saved in the phone or in the computer. Here is the logcat shown for my application and I would like to actually save the Pressure and Size in to an xml file under the Pressure/Size tag. How can I do that?

04-04 02:38:45.057: I/System.out(14272): Pressure 0.23333335
04-04 02:38:45.057: I/System.out(14272): Size 0.227451
04-04 02:38:46.217: I/System.out(14272): Pressure 0.20000002
04-04 02:38:46.217: I/System.out(14272): Size 0.22352943
04-04 02:38:46.702: I/System.out(14272): Pressure 0.26666668
04-04 02:38:46.702: I/System.out(14272): Size 0.27450982
04-04 02:38:47.222: I/System.out(14272): Pressure 0.23333335
04-04 02:38:47.222: I/System.out(14272): Size 0.26666668
04-04 02:38:47.657: I/System.out(14272): Pressure 0.23333335
04-04 02:38:47.657: I/System.out(14272): Size 0.23137257
04-04 02:38:48.087: I/System.out(14272): Pressure 0.16666667
04-04 02:38:48.087: I/System.out(14272): Size 0.16862746
04-04 02:38:48.502: I/System.out(14272): Pressure 0.3
04-04 02:38:48.502: I/System.out(14272): Size 0.3019608
04-04 02:38:48.907: I/System.out(14272): Pressure 0.23333335
04-04 02:38:48.907: I/System.out(14272): Size 0.2392157
04-04 02:38:49.267: I/System.out(14272): Pressure 0.23333335
04-04 02:38:49.267: I/System.out(14272): Size 0.25882354
04-04 02:38:49.732: I/System.out(14272): Pressure 0.20000002
04-04 02:38:49.732: I/System.out(14272): Size 0.21568629
04-04 02:38:50.137: I/System.out(14272): Pressure 0.23333335
04-04 02:38:50.137: I/System.out(14272): Size 0.2509804
04-04 02:38:50.647: I/System.out(14272): Pressure 0.23333335
04-04 02:38:50.647: I/System.out(14272): Size 0.24705884
04-04 02:38:51.042: I/System.out(14272): Pressure 0.16666667
04-04 02:38:51.042: I/System.out(14272): Size 0.18823531
04-04 02:39:10.822: I/System.out(14272): Pressure 0.23333335
04-04 02:39:10.822: I/System.out(14272): Size 0.22352943
04-04 02:39:10.987: I/System.out(14272): Pressure 0.26666668
04-04 02:39:10.987: I/System.out(14272): Size 0.26666668
04-04 02:39:11.177: I/System.out(14272): Pressure 0.23333335
04-04 02:39:11.177: I/System.out(14272): Size 0.26666668
04-04 02:39:11.482: I/System.out(14272): Pressure 0.20000002
04-04 02:39:11.482: I/System.out(14272): Size 0.227451
04-04 02:39:11.787: I/System.out(14272): Pressure 0.23333335
04-04 02:39:11.787: I/System.out(14272): Size 0.21960786
04-04 02:39:12.137: I/System.out(14272): Pressure 0.23333335
04-04 02:39:12.137: I/System.out(14272): Size 0.23529413
04-04 02:39:12.472: I/System.out(14272): Pressure 0.20000002
04-04 02:39:12.472: I/System.out(14272): Size 0.22352943
04-04 02:39:12.792: I/System.out(14272): Pressure 0.20000002
04-04 02:39:12.792: I/System.out(14272): Size 0.1764706
04-04 02:39:13.122: I/System.out(14272): Pressure 0.23333335
04-04 02:39:13.122: I/System.out(14272): Size 0.2627451
04-04 02:39:13.937: I/System.out(14272): Pressure 0.26666668
04-04 02:39:13.937: I/System.out(14272): Size 0.27450982
04-04 02:39:14.472: I/System.out(14272): Pressure 0.16666667
04-04 02:39:14.472: I/System.out(14272): Size 0.13725491
04-04 02:39:15.007: I/System.out(14272): Pressure 0.3
04-04 02:39:15.007: I/System.out(14272): Size 0.30588236
04-04 02:39:15.482: I/System.out(14272): Pressure 0.26666668
04-04 02:39:15.482: I/System.out(14272): Size 0.26666668
04-04 02:39:15.877: I/System.out(14272): Pressure 0.20000002
04-04 02:39:15.877: I/System.out(14272): Size 0.24705884
04-04 02:39:16.097: I/System.out(14272): Pressure 0.26666668
04-04 02:39:16.097: I/System.out(14272): Size 0.26666668
SaberTooth
  • 157
  • 1
  • 4
  • 15
  • [whathaveyoutried.com](http://www.whathaveyoutried.com/) Google: "android write to xml file". – dymmeh Apr 03 '13 at 20:49

2 Answers2

0

You can't on modern android. As of 4.2, apps can't access the logfile anymore. YOu'll have to do this on the PC.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • After MotionEvent occurs a text is shown in a TextView. How can I write that text into an xml file? – SaberTooth Apr 03 '13 at 20:55
  • Oh, you can do a variety of work arounds- write your own logging function that writes to a file on the SD card, for example. And then you could do it in XML more easily. You just can't see what's being written to logcat, by your app or any other. – Gabe Sechan Apr 03 '13 at 20:58
0

A Perl script to run on your local PC using :

Require the logcat output in input_file.log

#!/usr/bin/perl

use strict; use warnings;
use XML::Simple;

my $h = {};

print "<?xml version='1.0' encoding='UTF-8'?>\n";

while (<>) {
    chomp;
    my @F = split;
    push @{ $h->{item} }, {
        date => "$F[0] $F[1]",
        system => $F[2],
        $F[3] => $F[4]
    }
}

my $xs = new XML::Simple;
my $xml = $xs->XMLout($h, NoAttr => 1, RootName => "tree");
print $xml;

Usage

./script.pl < input_file.log

Output

<?xml version='1.0' encoding='UTF-8'?>
<tree>
  <item>
    <Pressure>0.23333335</Pressure>
    <date>04-04 02:38:45.057:</date>
    <system>I/System.out(14272):</system>
  </item>
  <item>
    <Size>0.227451</Size>
    <date>04-04 02:38:45.057:</date>
    <system>I/System.out(14272):</system>
  </item>
  <item>
    <Pressure>0.20000002</Pressure>
    <date>04-04 02:38:46.217:</date>
    <system>I/System.out(14272):</system>
    (...)
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223