cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-8198) Unified console output logic for core platforms
Date Thu, 10 Sep 2015 16:36:45 GMT

    [ https://issues.apache.org/jira/browse/CB-8198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14739071#comment-14739071
] 

ASF GitHub Bot commented on CB-8198:
------------------------------------

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.


> Unified console output logic for core platforms
> -----------------------------------------------
>
>                 Key: CB-8198
>                 URL: https://issues.apache.org/jira/browse/CB-8198
>             Project: Apache Cordova
>          Issue Type: New Feature
>          Components: Android, iOS, Windows, WP8
>            Reporter: Vladimir Kotikov
>            Assignee: Sergey Shakhnazarov
>
> Currently all major platform scripts doesn't recognize trace levels and always logging
all their output to console.
> This could be unuseful, especially when a huge output from build tools is put to console
(ant build/xcodebuild output is really huge and in most cases is unnecessary)
> I propose to unify the way we write messages to console output:
> 1. Pass verbosity arguments (-d, --debug ) downstream to platform scripts.
> 2. Introduce special Log class which is shared across platform scripts
>     * automatically detects trace level according to command line arguments;
>     * support of output redirection (file, other) in the future?
> 3. Add support for the following verbosity levels: Error, Normal, Debug
>     * by default: Error and Normal messages are traced
>     * -silent: only Error messages are traced
>     * -verbose: everything is traced



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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


Mime
View raw message