You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by alsorokin <gi...@git.apache.org> on 2015/08/04 18:29:41 UTC

[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

GitHub user alsorokin opened a pull request:

    https://github.com/apache/cordova-windows/pull/107

    CB-8936 Added logging functionality

    https://issues.apache.org/jira/browse/CB-8936

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/MSOpenTech/cordova-windows CB-8936

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-windows/pull/107.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #107
    
----
commit d833994e12de6cdd74b497ef24ed4c6e38811598
Author: alsorokin <al...@akvelon.com>
Date:   2015-08-04T16:26:11Z

    CB-8936 Added logging functionality

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36817029
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,227 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs'),
    +    ROOT    = path.join(__dirname, '..', '..');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
    +    console.log('Continuously prints the windows logs output to the command line.');
    +    process.exit(0);
    +};
    +
    +function getElementValue(et, element, attribute) {
    +    var result;
    +
    +    var found = et.findall(element);
    +    if (found.length > 0) {
    +        if (!!attribute) {
    +            result = found[0].get(attribute);
    +        } else {
    +            result = found[0].text; 
    +        }
    +    }
    +
    +    return result;
    +}
    +
    +function parseEvents(output) {
    +    var etree = et.parse(output);
    +    var events = etree.getroot().findall('./Event');
    +    var results = [];
    +
    +    events.forEach(function (event) {
    +        // Get only unhandled exceptions from Admin log
    +        if (getElementValue(event, './System/Channel') === 'Microsoft-Windows-AppHost/Admin' &&
    +            typeof getElementValue(event, './UserData/WWAUnhandledApplicationException') === 'undefined') {
    --- End diff --
    
    I tested and my app which has an unhandledexception does not end up emitting an event in the log - why?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36318952
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,226 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Logging enabled, now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.join('cordova', 'log'));
    --- End diff --
    
    Won't this print out "cordova\log" on Windows?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by alsorokin <gi...@git.apache.org>.
Github user alsorokin commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-127672899
  
    @nikhilkh thanks for instant reply! Fixed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-127668674
  
    @robpaveza @purplecabbage Please review and see if it can be merged for the current release.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-129679597
  
    I was able to run the log script, but I haven't yet been able to get it to print some logs. Do you have any sample output?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36817197
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,227 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs'),
    +    ROOT    = path.join(__dirname, '..', '..');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
    +    console.log('Continuously prints the windows logs output to the command line.');
    +    process.exit(0);
    +};
    +
    +function getElementValue(et, element, attribute) {
    +    var result;
    +
    +    var found = et.findall(element);
    +    if (found.length > 0) {
    +        if (!!attribute) {
    +            result = found[0].get(attribute);
    +        } else {
    +            result = found[0].text; 
    +        }
    +    }
    +
    +    return result;
    +}
    +
    +function parseEvents(output) {
    +    var etree = et.parse(output);
    +    var events = etree.getroot().findall('./Event');
    +    var results = [];
    +
    +    events.forEach(function (event) {
    +        // Get only unhandled exceptions from Admin log
    +        if (getElementValue(event, './System/Channel') === 'Microsoft-Windows-AppHost/Admin' &&
    +            typeof getElementValue(event, './UserData/WWAUnhandledApplicationException') === 'undefined') {
    --- End diff --
    
    Here's the event that got generated:
    + System 
    
      - Provider 
    
       [ Name]  Microsoft-Windows-AppHost 
       [ Guid]  {98E0765D-8C42-44A3-A57B-760D7F93225A} 
     
       EventID 127 
     
       Version 0 
     
       Level 2 
     
       Task 8 
     
       Opcode 12 
     
       Keywords 0x8000000000000001 
     
      - TimeCreated 
    
       [ SystemTime]  2015-08-12T00:47:00.808688300Z 
     
       EventRecordID 100 
     
       Correlation 
     
      - Execution 
    
       [ ProcessID]  10600 
       [ ThreadID]  14852 
     
       Channel Microsoft-Windows-AppHost/Admin 
     
       Computer nikhilkh005.redmond.corp.microsoft.com 
     
      - Security 
    
       [ UserID]  S-1-5-21-2127521184-1604012920-1887927527-2523208 
     
    
    - UserData 
    
      - WWATerminateApplication 
    
       DisplayName HelloCordova 
     
       ApplicationName io.cordova.hellocordova 
     
       AppUserModelId io.cordova.hellocordova_h35559jr9hy9m!io.cordova.hellocordova 
     
       PackageFullName io.cordova.hellocordova_0.0.1.0_neutral__h35559jr9hy9m 
     
       ProcessId 10600 
     
       ErrorDescription {"description":"'platform' is undefined","number":-2146823279,"stack":"ReferenceError: 'platform' is undefined\n at activationHandler (ms-appx://io.cordova.hellocordova/www/cordova.js:1320:17)\n at dispatchOne (ms-appx://microsoft.winjs.2.0/js/base.js:9416:25)\n at dispatchEvent (ms-appx://microsoft.winjs.2.0/js/base.js:9415:21)\n at drainOneEvent (ms-appx://microsoft.winjs.2.0/js/base.js:9469:13)\n at drainQueue (ms-appx://microsoft.winjs.2.0/js/base.js:9486:9)\n at Anonymous function (ms-appx://microsoft.winjs.2.0/js/base.js:2952:17)\n at state_running.enter (ms-appx://microsoft.winjs.2.0/js/base.js:2951:13)\n at _setState (ms-appx://microsoft.winjs.2.0/js/base.js:2667:13)\n at Anonymous function (ms-appx://microsoft.winjs.2.0/js/base.js:2866:13)\n at _execute (ms-appx://microsoft.winjs.2.0/js/base.js:2642:13)"} 
     
       DocumentFile /www/index.html 
     
       StackTrace ReferenceError: 'platform' is undefined at activationHandler (ms-appx://io.cordova.hellocordova/www/cordova.js:1320:17) at dispatchOne (ms-appx://microsoft.winjs.2.0/js/base.js:9416:25) at dispatchEvent (ms-appx://microsoft.winjs.2.0/js/base.js:9415:21) at drainOneEvent (ms-appx://microsoft.winjs.2.0/js/base.js:9469:13) at drainQueue (ms-appx://microsoft.winjs.2.0/js/base.js:9486:9) at Anonymous function (ms-appx://microsoft.winjs.2.0/js/base.js:2952:17) at state_running.enter (ms-appx://microsoft.winjs.2.0/js/base.js:2951:13) at _setState (ms-appx://microsoft.winjs.2.0/js/base.js:2667:13) at Anonymous function (ms-appx://microsoft.winjs.2.0/js/base.js:2866:13) at _execute (ms-appx://microsoft.winjs.2.0/js/base.js:2642:13)  
     
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36817293
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,227 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs'),
    +    ROOT    = path.join(__dirname, '..', '..');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
    +    console.log('Continuously prints the windows logs output to the command line.');
    +    process.exit(0);
    +};
    +
    +function getElementValue(et, element, attribute) {
    +    var result;
    +
    +    var found = et.findall(element);
    +    if (found.length > 0) {
    +        if (!!attribute) {
    +            result = found[0].get(attribute);
    +        } else {
    +            result = found[0].text; 
    +        }
    +    }
    +
    +    return result;
    +}
    +
    +function parseEvents(output) {
    +    var etree = et.parse(output);
    +    var events = etree.getroot().findall('./Event');
    +    var results = [];
    +
    +    events.forEach(function (event) {
    +        // Get only unhandled exceptions from Admin log
    +        if (getElementValue(event, './System/Channel') === 'Microsoft-Windows-AppHost/Admin' &&
    +            typeof getElementValue(event, './UserData/WWAUnhandledApplicationException') === 'undefined') {
    --- End diff --
    
    You might want to look for both UnhandledApplicationException and WWATerminateApplication 



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-130127033
  
    How do you plan to use this in our CI setup? I see a couple of issues - it requires Ctrl+c to exit, admin permissions. Should there be another mode of operation? log start -> enables the log, logs it to a file. log end -> dumps the log text file to console after disabling the log. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36817410
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,227 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs'),
    +    ROOT    = path.join(__dirname, '..', '..');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
    +    console.log('Continuously prints the windows logs output to the command line.');
    +    process.exit(0);
    +};
    +
    +function getElementValue(et, element, attribute) {
    +    var result;
    +
    +    var found = et.findall(element);
    +    if (found.length > 0) {
    +        if (!!attribute) {
    +            result = found[0].get(attribute);
    +        } else {
    +            result = found[0].text; 
    +        }
    +    }
    +
    +    return result;
    +}
    +
    +function parseEvents(output) {
    +    var etree = et.parse(output);
    +    var events = etree.getroot().findall('./Event');
    +    var results = [];
    +
    +    events.forEach(function (event) {
    +        // Get only unhandled exceptions from Admin log
    +        if (getElementValue(event, './System/Channel') === 'Microsoft-Windows-AppHost/Admin' &&
    +            typeof getElementValue(event, './UserData/WWAUnhandledApplicationException') === 'undefined') {
    +            return;
    +        }
    +
    +        var result = {
    +            channel: getElementValue(event, './System/Channel'),
    +            timeCreated: getElementValue(event, './System/TimeCreated', 'SystemTime'),
    +            pid: getElementValue(event, './System/Execution', 'ProcessID'),
    +            proc: getElementValue(event, './UserData/WWADevToolBarLog/DisplayName'),
    +            source: getElementValue(event, './UserData/WWADevToolBarLog/Source'),
    +            documentFile: getElementValue(event, './UserData/WWADevToolBarLog/DocumentFile') ||
    +                          getElementValue(event, './UserData/WWAUnhandledApplicationException/DocumentFile'),
    +            line: getElementValue(event, './UserData/WWADevToolBarLog/Line'),
    +            column: getElementValue(event, './UserData/WWADevToolBarLog/Column'),
    +            sourceFile: getElementValue(event, './UserData/WWAUnhandledApplicationException/SourceFile'),
    +            sourceLine: getElementValue(event, './UserData/WWAUnhandledApplicationException/SourceLine'),
    +            sourceColumn: getElementValue(event, './UserData/WWAUnhandledApplicationException/SourceColumn'),
    +            message: getElementValue(event, './UserData/WWADevToolBarLog/Message'),
    +            displayName: getElementValue(event, './UserData/WWAUnhandledApplicationException/DisplayName'),
    +            appName: getElementValue(event, './UserData/WWAUnhandledApplicationException/ApplicationName'),
    +            errorType: getElementValue(event, './UserData/WWAUnhandledApplicationException/ErrorType'),
    +            errorDescription: getElementValue(event, './UserData/WWAUnhandledApplicationException/ErrorDescription'),
    +            stackTrace: getElementValue(event, './UserData/WWAUnhandledApplicationException/StackTrace'),
    +        };
    + 
    +        results.push(result);
    +    });
    +    
    +    return results;
    +}
    +
    +function formatField(event, fieldName, fieldShownName, offset) {
    +    var whitespace = '', // to align all field values
    +        multiLineWhitespace = ' '; // to align multiline fields (i.e. Stack Trace) correctly
    +    for (var i = 0; i < offset; i++) {
    +        if (i >= fieldShownName.length) {
    +            whitespace += ' ';
    +        }
    +        multiLineWhitespace += ' ';
    +    }
    +
    +    if (event.hasOwnProperty(fieldName) && (typeof event[fieldName] !== 'undefined')) {
    +        event[fieldName] = event[fieldName].replace(/\n\s*/g, '\n' + multiLineWhitespace);
    +        return ('\n' + fieldShownName + ':' + whitespace + event[fieldName]).replace(/\n$/m, '');
    +    }
    +    return '';
    +}
    +
    +function stringifyEvent(event) {
    +    if (typeof event === 'undefined') {
    +        return;
    +    }
    +
    +    var result = '',
    +        offset = 18;
    +
    +    result += formatField(event, 'channel', 'Channel', offset);
    --- End diff --
    
    I think having a simplified CSV event format is more readable as one needs to scroll through lots of console messages than field:value format you are currently using.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by alsorokin <gi...@git.apache.org>.
Github user alsorokin commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36328641
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,226 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Logging enabled, now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.join('cordova', 'log'));
    --- End diff --
    
    Fixed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by alsorokin <gi...@git.apache.org>.
Github user alsorokin commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-130074754
  
    @dblotsky yes, it works similar to adnroid's logcat. You run log script and get continuously updating logs in your command propmpt.
    
    So, the step-by-step guide to getting logs would look like:
    
    Prepare sample app:
    `cordova create foo`
    `cd foo`
    `cordova platform add https://github.com/MSOpenTech/cordova-windows#CB-8936`
    
    Run following in separate command prompt:
    `platforms\windows\cordova\log.bat`
    it will say `Now printing logs. To stop, please press Ctrl+C once..`
    
    Then just run the app:
    `cordova run`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-windows/pull/107


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-127668967
  
    @alsorokin Looks like there are jshint failures


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by alsorokin <gi...@git.apache.org>.
Github user alsorokin commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36398856
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,226 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Logging enabled, now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    --- End diff --
    
    @robpaveza Actually, I just modified the script so that it wouldn't fail if it hasn't administrator privileges, but only warn about that and try to show the logs that are already enabled.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-130120783
  
    I ran this and I got this:
    ```
    λ platforms\windows\cordova\log
    Cannot enable log channel: Microsoft-Windows-AppHost/Admin
    Try running the script with administrator privileges.
    Cannot enable log channel: Microsoft-Windows-AppHost/ApplicationTracing
    Try running the script with administrator privileges.
    Now printing logs. To stop, please press Ctrl+C once.
    ```
    It's not a big deal - but maybe we should just end the program here because both log providers were not being enabled and skip the 'Now printing logs.'



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-130007325
  
    I tried running with Administrator privileges and without them, but I think something was wrong with how I ran the app. Does the log run until stopped by design?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by alsorokin <gi...@git.apache.org>.
Github user alsorokin commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36327824
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,226 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Logging enabled, now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    --- End diff --
    
    No. `wevtutil` requires admin privileges when enabling or disabling a channel, so the whole script wouldn't run without it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-130130901
  
    I merged this change in, but we still need a task to get Medic to run it and kill it in a reasonable amount of time.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36817771
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,227 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs'),
    +    ROOT    = path.join(__dirname, '..', '..');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    +        cp.exec(command, function (error, stdout, stderr) {
    +            if (error) {
    +                throw new Error('Failed to run wevtutil command. ' + error);
    +            } else {
    +                parseEvents(stdout).forEach(function (evt) {
    +                    startTime = evt.timeCreated;
    +                    console.log(stringifyEvent(evt));
    +                });
    +            }
    +        });
    +    }, 1000);
    +}
    +
    +module.exports.help = function() {
    +    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
    +    console.log('Continuously prints the windows logs output to the command line.');
    +    process.exit(0);
    +};
    +
    +function getElementValue(et, element, attribute) {
    +    var result;
    +
    +    var found = et.findall(element);
    +    if (found.length > 0) {
    +        if (!!attribute) {
    +            result = found[0].get(attribute);
    +        } else {
    +            result = found[0].text; 
    +        }
    +    }
    +
    +    return result;
    +}
    +
    +function parseEvents(output) {
    +    var etree = et.parse(output);
    +    var events = etree.getroot().findall('./Event');
    +    var results = [];
    +
    +    events.forEach(function (event) {
    +        // Get only unhandled exceptions from Admin log
    +        if (getElementValue(event, './System/Channel') === 'Microsoft-Windows-AppHost/Admin' &&
    +            typeof getElementValue(event, './UserData/WWAUnhandledApplicationException') === 'undefined') {
    +            return;
    +        }
    +
    +        var result = {
    +            channel: getElementValue(event, './System/Channel'),
    +            timeCreated: getElementValue(event, './System/TimeCreated', 'SystemTime'),
    +            pid: getElementValue(event, './System/Execution', 'ProcessID'),
    +            proc: getElementValue(event, './UserData/WWADevToolBarLog/DisplayName'),
    +            source: getElementValue(event, './UserData/WWADevToolBarLog/Source'),
    +            documentFile: getElementValue(event, './UserData/WWADevToolBarLog/DocumentFile') ||
    +                          getElementValue(event, './UserData/WWAUnhandledApplicationException/DocumentFile'),
    +            line: getElementValue(event, './UserData/WWADevToolBarLog/Line'),
    +            column: getElementValue(event, './UserData/WWADevToolBarLog/Column'),
    +            sourceFile: getElementValue(event, './UserData/WWAUnhandledApplicationException/SourceFile'),
    +            sourceLine: getElementValue(event, './UserData/WWAUnhandledApplicationException/SourceLine'),
    +            sourceColumn: getElementValue(event, './UserData/WWAUnhandledApplicationException/SourceColumn'),
    +            message: getElementValue(event, './UserData/WWADevToolBarLog/Message'),
    +            displayName: getElementValue(event, './UserData/WWAUnhandledApplicationException/DisplayName'),
    +            appName: getElementValue(event, './UserData/WWAUnhandledApplicationException/ApplicationName'),
    +            errorType: getElementValue(event, './UserData/WWAUnhandledApplicationException/ErrorType'),
    +            errorDescription: getElementValue(event, './UserData/WWAUnhandledApplicationException/ErrorDescription'),
    +            stackTrace: getElementValue(event, './UserData/WWAUnhandledApplicationException/StackTrace'),
    +        };
    + 
    +        results.push(result);
    +    });
    +    
    +    return results;
    +}
    +
    +function formatField(event, fieldName, fieldShownName, offset) {
    +    var whitespace = '', // to align all field values
    +        multiLineWhitespace = ' '; // to align multiline fields (i.e. Stack Trace) correctly
    +    for (var i = 0; i < offset; i++) {
    +        if (i >= fieldShownName.length) {
    +            whitespace += ' ';
    +        }
    +        multiLineWhitespace += ' ';
    +    }
    +
    +    if (event.hasOwnProperty(fieldName) && (typeof event[fieldName] !== 'undefined')) {
    +        event[fieldName] = event[fieldName].replace(/\n\s*/g, '\n' + multiLineWhitespace);
    +        return ('\n' + fieldShownName + ':' + whitespace + event[fieldName]).replace(/\n$/m, '');
    +    }
    +    return '';
    +}
    +
    +function stringifyEvent(event) {
    +    if (typeof event === 'undefined') {
    +        return;
    +    }
    +
    +    var result = '',
    +        offset = 18;
    +
    +    result += formatField(event, 'channel', 'Channel', offset);
    --- End diff --
    
    On 2nd thoughts - this can be refined later - lets get it out there.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36816504
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,226 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Logging enabled, now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    --- End diff --
    
    If both logs are not enabled and we fail to enable them due to admin issues - we should exit.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by alsorokin <gi...@git.apache.org>.
Github user alsorokin commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-129778483
  
    @dblotsky do you run it with administrator privileges?
    
    Here you go with the sample output from mobilespec app:
    https://gist.github.com/alsorokin/00070ddfddcef6334a71



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/107#discussion_r36318858
  
    --- Diff: template/cordova/lib/log.js ---
    @@ -0,0 +1,226 @@
    +/*
    +       Licensed to the Apache Software Foundation (ASF) under one
    +       or more contributor license agreements.  See the NOTICE file
    +       distributed with this work for additional information
    +       regarding copyright ownership.  The ASF licenses this file
    +       to you under the Apache License, Version 2.0 (the
    +       "License"); you may not use this file except in compliance
    +       with the License.  You may obtain a copy of the License at
    +
    +         http://www.apache.org/licenses/LICENSE-2.0
    +
    +       Unless required by applicable law or agreed to in writing,
    +       software distributed under the License is distributed on an
    +       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +       KIND, either express or implied.  See the License for the
    +       specific language governing permissions and limitations
    +       under the License.
    +*/
    +
    +var path    = require('path'),
    +    et      = require('elementtree'),
    +    Q       = require('q'),
    +    cp      = require('child_process'),
    +    shelljs = require('shelljs');
    +
    +var appTracingLogInitialState = null,
    +    adminLogInitialState = null;
    +
    +/*
    + * Gets windows AppHost/ApplicationTracing and AppHost/Admin logs
    + * and prints them to console
    + */
    +module.exports.run = function() {
    +    getLogState('Microsoft-Windows-AppHost/ApplicationTracing').then(function (state) {
    +        appTracingLogInitialState = state;
    +        return getLogState('Microsoft-Windows-AppHost/Admin');
    +    }).then(function(state) {
    +        adminLogInitialState = state;
    +        return enableLogging('Microsoft-Windows-AppHost/Admin');
    +    }).then(function () {
    +        return enableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).then(function () {
    +        console.log('Logging enabled, now printing logs. To stop, please press Ctrl+C once.');
    +        startLogging('Microsoft-Windows-AppHost/Admin');
    +        startLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +    }).catch(function (error) {
    +        console.error(error);
    +    });
    +
    +    // Disable logs before exiting
    +    process.on('exit', function () {
    +        if ((appTracingLogInitialState !== null) && !appTracingLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/ApplicationTracing');
    +        }
    +        if ((adminLogInitialState !== null) && !adminLogInitialState) {
    +            disableLogging('Microsoft-Windows-AppHost/Admin');
    +        }
    +    });
    +
    +    // Catch Ctrl+C event and exit gracefully
    +    process.on('SIGINT', function () {
    +        process.exit(2);
    +    });
    +
    +    // Catch uncaught exceptions, print trace, then exit gracefully
    +    process.on('uncaughtException', function(e) {
    +        console.log(e.stack);
    +        process.exit(99);
    +    });
    +};
    +
    +function startLogging(channel) {
    +    var startTime = new Date().toISOString();
    +    setInterval(function() {
    +        var command = 'wevtutil qe ' + channel + ' /q:"*[System [(TimeCreated [@SystemTime>\'' + startTime + '\'])]]" /e:root';
    --- End diff --
    
    Will this run when not running as an administrator?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-windows pull request: CB-8936 Added logging functionality

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on the pull request:

    https://github.com/apache/cordova-windows/pull/107#issuecomment-130131376
  
    Another option is to make it dump the log and exit unless a special flag is provided.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org