Skip to content

Instantly share code, notes, and snippets.

@hrj
Last active June 13, 2023 13:26
Show Gist options
  • Save hrj/5983971 to your computer and use it in GitHub Desktop.
Save hrj/5983971 to your computer and use it in GitHub Desktop.
Log Shark

LogShark is a simple utility to collect logs from an Android device using a PC.

I created this to help Android developers collect information from their app's users. This information can be very useful for debugging purposes.

From Android version 4.1 (Jelly Bean) onwards, it has become difficult to collect this information through the device itself. Hence the need for an app that runs on the PC.

Note that the collection of information is entirely voluntary. Moreover, the user can (and should) review the information before sending it to developers or other people.

Pre-requisites

Java

Install the latest version of Java from java.com

Enable USB debugging on your Android device.

To do this, go to Settings -> Developer Options and turn the developer options on.

If Developer options is not available, you may need to research how to enable this option on your particular phone. The Nexus 4, for example, requires 7 taps on the Build Number to enable Developer Options

USB drivers

If you are using Microsoft Windows, you need to setup some USB drivers. See WindowsSetup below.

On other operating systems, no further setup is required.

Download

Download the LogShark jar file from here and save to any folder.

(Note for those unfamiliar with Java: you don't need to extract this file. The file is a fully self-contained Java executable).

Run

Connect your Android device to your PC using a USB cable. A notification should appear that says "USB debugging connected".

Now start the LogShark application. On Windows, you can simply double-click the jar file from an Explorer window. Similar interfaces should be available on other OSes.

If you prefer the command line, you can invoke it like this:

java -jar LogShark_0.1.jar

You should now see a window that explains what is happening. Upon successful completion, a file called logSharkOut.txt should be created. This file contains the log history of the Android device.

Screenshot

On Android 4.1+ devices, a prompt will be shown on the device to authorize the connection. You need to accept this authorization for LogShark to function.

Appendix

Windows Setup

On Windows you need to do some extra configuration.

First, download and install this app called zadig. This app allows you install libusbx device drivers for a specific USB device.

Windows XP users should download zadig_xp

Windows Vista, Win 7, Win 8 users should download zadig

After downloading the above, connect your Android device and run the zadig application. In the zadig main window select your Android device and select WinUSB (v6.1.xxx) and then click Install Driver.

That's it!

Now, LogShark should be able to work with your Android device.

Changelog

Version 0.1 : 12 July 2013

First cut.

Roadmap

  • Filtering by verbosity (error, debug, etc)
  • Filtering by app, tag, time, etc.
  • Open-source
@Steevow
Copy link

Steevow commented May 15, 2015

Thanks for LogShark.

Something is amiss.
I turned on usb debugging and disabled usb storage, but LogShark complains it cannot claim the interface. It finds the device. With USB debugging disabled LogShark can't find the device.

Found Android device. Connecting...
ERROR Couldn't claim Android's USB interface. Another process is probably using it.
Check if ADB is running, for example.

I did install the Zadig driver, it says successful. I tried charge mode only on the usb options screen. I tried with and without usb debugging enabled. I even tried with developer options disabled. No difference.

I think you're right about ADB. But I sure don't see how to disable it. Android 4.4.2. It worked on an older android device, I have the LogShark logs.

Any ideas? I am eager to try your log retriever. I do not have root, btw. But I do have dev options on. This windows 7 machine does not have the Android SDK installed.

@javatlacati
Copy link

Exception in thread "main" java.lang.NullPointerException
at de.ailis.usb4java.AbstractIrpQueue.add(AbstractIrpQueue.java:75)
at de.ailis.usb4java.Pipe.asyncSubmit(Pipe.java:197)
at de.ailis.usb4java.Pipe.asyncSubmit(Pipe.java:175)
at de.ailis.usb4java.Pipe.syncSubmit(Pipe.java:161)
at logshark.ADBRx.rcvData(ADB.scala:194)
at logshark.ADBRx.rcvMessage(ADB.scala:163)
at logshark.AdbManager.readStream(AdbManager.scala:138)
at logshark.Main$$anonfun$readLogs$1.apply(Main.scala:93)
at logshark.Main$$anonfun$readLogs$1.apply(Main.scala:91)
at scala.Option.map(Option.scala:145)
at logshark.Main$.readLogs(Main.scala:91)
at logshark.Main$.main(Main.scala:63)
at logshark.Main.main(Main.scala)

@teapotandcake
Copy link

I'm getting the following error:

LogShark (0.1). Copyright 2013 Harshad R.J.
Output file location: C:[---path---]\logSharkOut.txt
Found Android device. Connecting...
Sending a new key to device. Please authorize from device.
Waiting for response from device...
Waiting for response from device...
Connection established with device
ERROR Did't receive OKAY msg from device
ERROR Couldn't receive logs from Android device.

The thing is, the prompt to allow USB debugging appears on my phone's screen, and I click OK. But for some reason LogShark interprets it as NO anyway?

The phone is Samsung Galaxy S4 running Lollipop 5.0.1. The computer is Win7. I've installed Zadig and freshly updated Java. Using original Samsung USB cable. Phone is not rooted.
What could be the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment