arnaucube
arnaucube/commonroutesServerPublic Self-hosted repository
commonroutesServer/www/platforms/android/cordova/lib/log.js
www/platforms/android/cordova/lib/log.jsRaw
 1#!/usr/bin/env node
 2
 3/*
 4       Licensed to the Apache Software Foundation (ASF) under one
 5       or more contributor license agreements.  See the NOTICE file
 6       distributed with this work for additional information
 7       regarding copyright ownership.  The ASF licenses this file
 8       to you under the Apache License, Version 2.0 (the
 9       "License"); you may not use this file except in compliance
10       with the License.  You may obtain a copy of the License at
11
12         http://www.apache.org/licenses/LICENSE-2.0
13
14       Unless required by applicable law or agreed to in writing,
15       software distributed under the License is distributed on an
16       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17       KIND, either express or implied.  See the License for the
18       specific language governing permissions and limitations
19       under the License.
20*/
21
22var path  = require('path'),
23    os  = require('os'),
24    Q     = require('q'),
25    child_process = require('child_process'),
26    ROOT  = path.join(__dirname, '..', '..');
27
28/*
29 * Starts running logcat in the shell.
30 * Returns a promise.
31 */
32module.exports.run = function() {
33    var d = Q.defer();
34    var adb = child_process.spawn('adb', ['logcat'], {cwd: os.tmpdir()});
35
36    adb.stdout.on('data', function(data) {
37        var lines = data ? data.toString().split('\n') : [];
38        var out = lines.filter(function(x) { return x.indexOf('nativeGetEnabledTags') < 0; });
39        console.log(out.join('\n'));
40    });
41
42    adb.stderr.on('data', console.error);
43    adb.on('close', function(code) {
44        if (code > 0) {
45            d.reject('Failed to run logcat command.');
46        } else d.resolve();
47    });
48
49    return d.promise;
50};
51
52module.exports.help = function() {
53    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
54    console.log('Gives the logcat output on the command line.');
55    process.exit(0);
56};