Last active
July 27, 2017 12:20
-
-
Save mikepenz/9e828b4f9728a7efd4eb3cddcf3daa22 to your computer and use it in GitHub Desktop.
android-gradle-logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gradle.taskGraph.afterTask { task, state -> | |
if (task. state.failure) { | |
println "$task.name FAILED PRINTING LOGS" | |
getDevicesAndReadLogs(500) | |
} | |
} | |
ext.getDevicesAndReadLogs = { count = 2500 -> | |
try { | |
def outstream = new ByteArrayOutputStream() | |
exec { | |
executable "sh" | |
workingDir '.' | |
args "-c", "adb devices -l" | |
standardOutput = outstream | |
} | |
outstream.toString().split("\n").each { | |
if (!it.contains("List of devices")) { | |
def parts = it.split(" "); | |
readTestLogs(parts[0], count); | |
} | |
} | |
} catch (Exception ex) { | |
println("Failed to do getDevicesAndReadLogs because of: " + ex) | |
} | |
} | |
ext.readTestLogs = { device, count -> | |
try { | |
def outstream = new ByteArrayOutputStream() | |
exec { | |
executable "sh" | |
workingDir '.' | |
args "-c", "adb -s " + device + " shell logcat -n " + count + " -d '*:E'" | |
standardOutput = outstream | |
} | |
outstream.toString().split("\n").each { | |
println(it); | |
} | |
} catch (Exception ex) { | |
println("Failed to read log for " + device + " because of: " + ex) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment