FileConnectionAppenderin Microlog. I wanted to separate the logging part from the actual file writing. The logging should be in an abstract super class, while the file writing should be in the the concrete class. The purpose of this exercise would of course to be to support file logging on both Java ME and Android platform.
It took some time to create a good structure in the new
FileConnectionAppender. When this was done, it was a piece of cake to create the
FileAppender(for Android). I used the Eclipse class wizard to create a sub-class to
AbstractFileAppender. Most of the time was spent browsing the Internet and looking in the Android documentation. Then it was a matter of implementing a handful of methods. I had never tested to create and write to a file on Android before, but I was curious and executed the code directly when most of the methods was finished. This excluded the
flush()method for example. The diagram below shows the new class structure.
The next step was to figure where to find the log file. It was not long time before I found a file with a
.imgextension. From some documents found on the Internet, I could gather that this was a disk image. But how do I read the data found in the disk image? As it turns out there is several ways to do this:
- Use the command line tool called
- Use the file browser found in Android DDMS (Dalvik Debug Monitor System)
- Use the file browser that is part of the Android plug-in for Eclipse.
You start by typing
ddmsin your shell window or command prompt, depending on your operating system. This will bring up the DDMS tool. Select the device and use the Device->File Explorer... menu to access the file explorer, see picture below. You could now browse the file system in your Android emulator. In our case we browse to
/data/data/net.sf.microlog.android.example/files. This is where you will find the file
microlog.txt. If you wish to see the content of the file, which I gather that you do, you press the button marked yellow below. This will pull the file out of the Android file system to your file system. You get the chance to select where you want to save. Pick up your favorite text editor to view the marvelous content of your log file.
It is as easy as this to view a file on the Android file system. I hope you found this tip helpful.