You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by daserge <gi...@git.apache.org> on 2015/09/10 17:35:15 UTC

[GitHub] cordova-cli pull request: CB-8198 Unified console output logic for...

GitHub user daserge opened a pull request:

    https://github.com/apache/cordova-cli/pull/222

    CB-8198 Unified console output logic for core platforms

    Added advanced ansi-based logger
    Redirected events to logger
    
    [Corresponding Lib updates PR](https://github.com/apache/cordova-lib/pull/306)
    [Jira issue](https://issues.apache.org/jira/browse/CB-8198)

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

    $ git pull https://github.com/MSOpenTech/cordova-cli CB-8198

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

    https://github.com/apache/cordova-cli/pull/222.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 #222
    
----
commit 3e4d5b05b2c08d9e781fa277b563e4c1a9833752
Author: daserge <v-...@microsoft.com>
Date:   2015-09-10T12:48:05Z

    CB-8198 Unified console output logic for core platforms
    
    Added advanced ansi-based logger
    Redirected events to logger

----


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39181763
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,112 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        message = error.message;
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    +        var codePrefix = 'code: ' + error.code
    +            + (isVerbose ? (' (' + error.getErrorCodeName() + ')') : '');
    +
    +        if(error.code === CordovaError.EXTERNAL_TOOL_ERROR && typeof error.context !== 'undefined') {
    +            var context = isVerbose
    +                ? (suffix + error.toString() + suffix)
    +                : ('\'' + error.context.cmdShortName + '\' ' + error.message);
    +
    +            message = codePrefix + ' ' + context;
    +        } else {
    +            message = codePrefix + ' ' + message;
    +        }
    +    }
    +
    +    return message;
    +}
    +
    +logger.log = function (logLevel, message) {
    +    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
    +        var isVerbose = this.logLevel === 'verbose';
    +        var prefix = this.prefixes[logLevel] ? this.prefixes[logLevel] + ': ' : '';
    +        suffix = '\n';
    +
    +        if(message instanceof Error) {
    +            message = formatError(message, isVerbose);
    +        }
    +
    +        message = prefix + message + suffix;
    +
    +        if (!this.cursor) {
    +            this.output.write(message);
    +        }
    +        if (this.output !== this.cursor.stream) {
    +            this.cursor = ansi(this.output, { enabled: colorEnabled });
    +        }
    +        var color = this.colors[logLevel];
    +        !!color && this.cursor.bold().fg[color]();
    +        this.cursor.write(message);
    +        this.cursor.reset();
    +    }
    +};
    +
    +logger.addLevel = function (level, severity, prefix, color) {
    +    this.levels[level] = severity;
    --- End diff --
    
    sorry - my bad.


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39182618
  
    --- Diff: package.json ---
    @@ -29,10 +29,11 @@
         "cli"
       ],
       "dependencies": {
    -    "cordova-lib": "5.3.1",
    -    "q": "1.0.1",
    +    "ansi": "^0.3.0",
    +    "cordova-lib": "5.2.0",
    --- End diff --
    
    Sorry, it's an overlook from my side.


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39191436
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,115 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var EOL = require('os').EOL;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        // Some error messages start with 'Error: ' prefix, so cut it off here
    +        // TODO: Update platforms code to remove such prefixes
    +        message = error.message && error.message.replace(/^error:\s+/i, '');
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    --- End diff --
    
    Consider refactoring this in CordovaError


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39177796
  
    --- Diff: package.json ---
    @@ -29,10 +29,11 @@
         "cli"
       ],
       "dependencies": {
    -    "cordova-lib": "5.3.1",
    -    "q": "1.0.1",
    +    "ansi": "^0.3.0",
    +    "cordova-lib": "5.2.0",
    --- End diff --
    
    It does not see correct to change this version.


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39178616
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,112 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        message = error.message;
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    +        var codePrefix = 'code: ' + error.code
    +            + (isVerbose ? (' (' + error.getErrorCodeName() + ')') : '');
    +
    +        if(error.code === CordovaError.EXTERNAL_TOOL_ERROR && typeof error.context !== 'undefined') {
    +            var context = isVerbose
    +                ? (suffix + error.toString() + suffix)
    +                : ('\'' + error.context.cmdShortName + '\' ' + error.message);
    +
    +            message = codePrefix + ' ' + context;
    +        } else {
    +            message = codePrefix + ' ' + message;
    +        }
    +    }
    +
    +    return message;
    +}
    +
    +logger.log = function (logLevel, message) {
    +    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
    +        var isVerbose = this.logLevel === 'verbose';
    +        var prefix = this.prefixes[logLevel] ? this.prefixes[logLevel] + ': ' : '';
    +        suffix = '\n';
    --- End diff --
    
    This should be require('OS').newline


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39179238
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,112 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        message = error.message;
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    +        var codePrefix = 'code: ' + error.code
    +            + (isVerbose ? (' (' + error.getErrorCodeName() + ')') : '');
    +
    +        if(error.code === CordovaError.EXTERNAL_TOOL_ERROR && typeof error.context !== 'undefined') {
    +            var context = isVerbose
    +                ? (suffix + error.toString() + suffix)
    +                : ('\'' + error.context.cmdShortName + '\' ' + error.message);
    +
    +            message = codePrefix + ' ' + context;
    +        } else {
    +            message = codePrefix + ' ' + message;
    +        }
    +    }
    +
    +    return message;
    +}
    +
    +logger.log = function (logLevel, message) {
    +    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
    +        var isVerbose = this.logLevel === 'verbose';
    +        var prefix = this.prefixes[logLevel] ? this.prefixes[logLevel] + ': ' : '';
    +        suffix = '\n';
    +
    +        if(message instanceof Error) {
    +            message = formatError(message, isVerbose);
    +        }
    +
    +        message = prefix + message + suffix;
    +
    +        if (!this.cursor) {
    +            this.output.write(message);
    +        }
    +        if (this.output !== this.cursor.stream) {
    +            this.cursor = ansi(this.output, { enabled: colorEnabled });
    +        }
    +        var color = this.colors[logLevel];
    +        !!color && this.cursor.bold().fg[color]();
    +        this.cursor.write(message);
    +        this.cursor.reset();
    +    }
    +};
    +
    +logger.addLevel = function (level, severity, prefix, color) {
    +    this.levels[level] = severity;
    --- End diff --
    
    It's odd that adding the level, ends up setting the current level to that value.


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39178786
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,112 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        message = error.message;
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    +        var codePrefix = 'code: ' + error.code
    +            + (isVerbose ? (' (' + error.getErrorCodeName() + ')') : '');
    +
    +        if(error.code === CordovaError.EXTERNAL_TOOL_ERROR && typeof error.context !== 'undefined') {
    +            var context = isVerbose
    +                ? (suffix + error.toString() + suffix)
    +                : ('\'' + error.context.cmdShortName + '\' ' + error.message);
    +
    +            message = codePrefix + ' ' + context;
    +        } else {
    +            message = codePrefix + ' ' + message;
    +        }
    +    }
    +
    +    return message;
    +}
    +
    +logger.log = function (logLevel, message) {
    +    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
    +        var isVerbose = this.logLevel === 'verbose';
    +        var prefix = this.prefixes[logLevel] ? this.prefixes[logLevel] + ': ' : '';
    +        suffix = '\n';
    +
    +        if(message instanceof Error) {
    +            message = formatError(message, isVerbose);
    +        }
    +
    +        message = prefix + message + suffix;
    --- End diff --
    
    Lot of current error messages (at least in platforms) start with the 'Error:' prefix. I propose we strip that out from the beginning of the message to ensure we do not have double prefixes. In the long run we should change the platform code not to have the prefix.


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39181657
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,112 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        message = error.message;
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    +        var codePrefix = 'code: ' + error.code
    +            + (isVerbose ? (' (' + error.getErrorCodeName() + ')') : '');
    +
    +        if(error.code === CordovaError.EXTERNAL_TOOL_ERROR && typeof error.context !== 'undefined') {
    +            var context = isVerbose
    +                ? (suffix + error.toString() + suffix)
    +                : ('\'' + error.context.cmdShortName + '\' ' + error.message);
    +
    +            message = codePrefix + ' ' + context;
    +        } else {
    +            message = codePrefix + ' ' + message;
    +        }
    +    }
    +
    +    return message;
    +}
    +
    +logger.log = function (logLevel, message) {
    +    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
    +        var isVerbose = this.logLevel === 'verbose';
    +        var prefix = this.prefixes[logLevel] ? this.prefixes[logLevel] + ': ' : '';
    +        suffix = '\n';
    +
    +        if(message instanceof Error) {
    +            message = formatError(message, isVerbose);
    +        }
    +
    +        message = prefix + message + suffix;
    +
    +        if (!this.cursor) {
    +            this.output.write(message);
    +        }
    +        if (this.output !== this.cursor.stream) {
    +            this.cursor = ansi(this.output, { enabled: colorEnabled });
    +        }
    +        var color = this.colors[logLevel];
    +        !!color && this.cursor.bold().fg[color]();
    +        this.cursor.write(message);
    +        this.cursor.reset();
    +    }
    +};
    +
    +logger.addLevel = function (level, severity, prefix, color) {
    +    this.levels[level] = severity;
    --- End diff --
    
    I believe it creates a dictionary of level-severity correspondence actually.
    Log level is set up in `setLevel`.


---
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-cli pull request: CB-8198 Unified console output logic for...

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

    https://github.com/apache/cordova-cli/pull/222#discussion_r39182442
  
    --- Diff: src/logger.js ---
    @@ -0,0 +1,112 @@
    +/*
    + 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 util = require('util'),
    +    ansi = require('ansi'),
    +    Stream = require('stream'),
    +    cordova_lib = require('cordova-lib'),
    +    CordovaError = cordova_lib.CordovaError;
    +
    +var logger = {
    +    levels: {},
    +    prefixes: {},
    +    colors: {},
    +    output: process.stdout
    +};
    +
    +logger.cursor = ansi(logger.output);
    +
    +function formatError(error, isVerbose) {
    +    var message = '';
    +    if(isVerbose) {
    +        message = error.stack;
    +    } else {
    +        message = error.message;
    +    }
    +
    +    if(error instanceof CordovaError && error.code !== CordovaError.UNKNOWN_ERROR) {
    +        var codePrefix = 'code: ' + error.code
    +            + (isVerbose ? (' (' + error.getErrorCodeName() + ')') : '');
    +
    +        if(error.code === CordovaError.EXTERNAL_TOOL_ERROR && typeof error.context !== 'undefined') {
    +            var context = isVerbose
    +                ? (suffix + error.toString() + suffix)
    +                : ('\'' + error.context.cmdShortName + '\' ' + error.message);
    +
    +            message = codePrefix + ' ' + context;
    +        } else {
    +            message = codePrefix + ' ' + message;
    +        }
    +    }
    +
    +    return message;
    +}
    +
    +logger.log = function (logLevel, message) {
    +    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
    +        var isVerbose = this.logLevel === 'verbose';
    +        var prefix = this.prefixes[logLevel] ? this.prefixes[logLevel] + ': ' : '';
    +        suffix = '\n';
    +
    +        if(message instanceof Error) {
    +            message = formatError(message, isVerbose);
    +        }
    +
    +        message = prefix + message + suffix;
    --- End diff --
    
    Makes sense.


---
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