cosysoft / device

Android Device API Based on ddmlib
Apache License 2.0
249 stars 65 forks source link

Adb Logcat write file #4

Open saikrishna321 opened 8 years ago

saikrishna321 commented 8 years ago

with the below code i could get the adb logs but how do i stop this logs .. and write them to a file as well ..

final LogCatFilter filter = new LogCatFilter("", "", "com.android", "",
        "", LogLevel.WARN);
final LogCatListener lcl = new LogCatListener() {
    @Override
    public void log(List<LogCatMessage> msgList) {
        for (LogCatMessage msg : msgList) {
            if (filter.matches(msg)) {
                System.out.println(msg);
            }
        }
    }
};

device.addLogCatListener(lcl);
Thread.sleep(60000);
cosyman commented 8 years ago

to stop logging,You can use device.removeLogCatListener removing it,or use a volatile flag variable to toggle whether deal log in log method

write to a file ...There are many ways

saikrishna321 commented 8 years ago

@cosyman i get the below error when fetching the logs

java.lang.IllegalStateException: No logcat header processed yet, failed to parse line: --------- beginning of /dev/log/system

    at com.android.ddmlib.logcat.LogCatMessageParser.processLogLines(LogCatMessageParser.java:123)
    at com.android.ddmlib.logcat.LogCatReceiverTask$LogCatOutputReceiver.processLogLines(LogCatReceiverTask.java:112)
    at com.android.ddmlib.logcat.LogCatReceiverTask$LogCatOutputReceiver.processNewLines(LogCatReceiverTask.java:107)
    at com.android.ddmlib.MultiLineReceiver.addOutput(MultiLineReceiver.java:100)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:519)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:382)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:353)
    at com.android.ddmlib.Device.executeShellCommand(Device.java:604)
    at com.android.ddmlib.logcat.LogCatReceiverTask.run(LogCatReceiverTask.java:75)
    at com.github.cosysoft.device.android.impl.AbstractDevice.addLogCatListener(AbstractDevice.java:770)
    at com.appium.utils.ADBLogs.testLogs(ADBLogs.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
cosyman commented 8 years ago

https://github.com/square/spoon/issues/302