Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 26 additions & 33 deletions lib/adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var fs = require('fs'),
spawn = require('child_process').spawn,
exec = require('child_process').exec,
env = require('./env'),
logcat = require('adbkit-logcat'),
lastOptions;

exports.launch = launch;
Expand All @@ -32,7 +33,7 @@ function tailLog(options,pid,callback) {
var android = env.find(options,callback),
adb = android && path.join(android.sdkPath,'platform-tools','adb'),
target = options.target === 'device' ? '-d' : '-e',
child = android && spawn(adb,[target,'logcat']),
child = android && spawn(adb,[target,'logcat', '-B']),
moveAhead = String(pid).length + 3,
logger = options.logger,
auto_exit = options.auto_exit,
Expand All @@ -50,50 +51,42 @@ function tailLog(options,pid,callback) {
}
}

child.stdout.on('data',function(buf){
buf = String(buf);
buf.split('\n').forEach(function(line){
if (!pid) {
var m = searchRegex.exec(line);
if (m) {
pid = m[1];
moveAhead = pid.length + 3;
}
return;
}
var idx = line.indexOf(pid+'): ');
if (idx<0) return;
var msg = filterLog(line.substring(idx+moveAhead).trim()),
label = line.substring(0,2);
if (!msg) return;
if (auto_exit && msg==='TI_EXIT') {
reader = logcat.readStream(child.stdout);
reader.on('entry', function(entry) {
if(pid == entry.pid) {
if (auto_exit && entry.message==='TI_EXIT') {
return finish();
}
switch (label) {
case 'I/':
logger('info',msg);
switch (entry.priority) {
case logcat.Priority.INFO:
logger('info',entry.message);
break;
case 'D/':
case logcat.Priority.DEBUG:
// filter out some android low-level stuff
if (/^(pt_debug|ion)\s*\:/.test(msg) || /^, tls=0x/.test(msg)) {
logger('trace',msg);
if (/^(pt_debug|ion)\s*\:/.test(entry.message) || /^, tls=0x/.test(entry.message)) {
logger('trace',entry.message);
}
else {
logger('debug',msg);
logger('debug',entry.message);
}
break;
case 'W/':
logger('warn',msg);
case logcat.Priority.WARN:
logger('warn',entry.message);
break;
case 'E/':
case 'F/':
logger('error',msg);
case logcat.Priority.ERROR:
case logcat.Priority.FATAL:
logger('error',entry.message);
break;
}
});
}

});
reader.on('error', function(err) {
finish
});
reader.on('finish', function(err) {
finish
});
child.on('error',finish);
child.on('close',finish);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "androidlib",
"version": "0.1.7",
"version": "0.1.8",
"description": "Android Utility Library",
"main": "index.js",
"scripts": {
Expand All @@ -20,6 +20,7 @@
"url": "https://github.com/appcelerator/androidlib/issues"
},
"dependencies": {
"adbkit-logcat": "~1.0.3",
"async": "~0.9.0",
"colors": "~0.6.2",
"commander": "~2.2.0",
Expand Down