console.error如何在内部工作?

时间:2017-12-06 14:54:58

标签: javascript console

我正在尝试在console.error(errorObject.stack)中打印错误堆栈跟踪,在console.log(errorObject.stack)中也是如此,区别在于console.log显示的信息少于console.error(),例如,

对于 console.log() ,它会打印:

    >console.log(error.stack)
    >VM93392:1 Error: Requested Resource was not mapped.
    at Object._createErrorObject (TestUtil.js:237)
    at Object.mapRestResponseError (TestUtil.js:231)
    at TestDataSource.js:90
    at Object.execCb (require.js:1670)
    at Module.check (require.js:971)
    at Module.enable (require.js:1212)
    at Module.init (require.js:870)
    at Object.require (require.js:1472)
    at requirejs (require.js:1754)
    at child.openRestError (TestDataSource.js:94)
    at child.openRestErrorStatus (TestDataSource.js:85)
    at options.error (TestDataSource.js:58)
    at options.error (MyUtil.js:5375)
    at Object.options.error (MyUtil.js:448)
    at fire (jquery-1.9.1.js:1037)
    at Object.fireWith [as rejectWith] (jquery-1.9.1.js:1148)
    at done (jquery-1.9.1.js:8076)
    at XMLHttpRequest.callback (jquery-1.9.1.js:8598)

对于 console.error ,它会从初始化开始打印日志跟踪:

    >console.error(error.stack)
    >VM93423:1 Error: Requested Resource was not mapped.
    at Object._createErrorObject (TestUtil.js:237)
    at Object.mapRestResponseError (TestUtil.js:231)
    at TestDataSource.js:90
    at Object.execCb (require.js:1670)
    at Module.check (require.js:971)
    at Module.enable (require.js:1212)
    at Module.init (require.js:870)
    at Object.require (require.js:1472)
    at requirejs (require.js:1754)
    at child.openRestError (TestDataSource.js:94)
    at child.openRestErrorStatus (TestDataSource.js:85)
    at options.error (TestDataSource.js:58)
    at options.error (MyUtil.js:5375)
    at Object.options.error (MyUtil.js:448)
    at fire (jquery-1.9.1.js:1037)
    at Object.fireWith [as rejectWith] (jquery-1.9.1.js:1148)
    at done (jquery-1.9.1.js:8076)
    at XMLHttpRequest.callback (jquery-1.9.1.js:8598)
    (anonymous) @   VM93423:1
    _createErrorObject  @   TestUtil.js:237
    mapRestResponseError    @   TestUtil.js:231
    (anonymous) @   TestDataSource.js:90
    execCb  @   require.js:1670
    check   @   require.js:971
    enable  @   require.js:1212
    init    @   require.js:870
    require @   require.js:1472
    requirejs   @   require.js:1754
    _openResponseRestError  @   TestDataSource.js:94
    _openRestResponseErrorStatus    @   TestDataSource.js:85
    options.error   @   TestDataSource.js:58
    options.error   @   MyUtil.js:5375
    options.error   @   MyUtil.js:448
    fire    @   jquery-1.9.1.js:1037
    fireWith    @   jquery-1.9.1.js:1148
    done    @   jquery-1.9.1.js:8076
    callback    @   jquery-1.9.1.js:8598
    XMLHttpRequest.send (async)     
    send    @   jquery-1.9.1.js:8526
    ajax    @   jquery-1.9.1.js:7978
    RESTDataSource.sync @   MyUtil.js:3820
    callback    @   jquery-1.9.1.js:8598
    XMLHttpRequest.send (async) (------> same trace till this part <----)
    send    @   jquery-1.9.1.js:8526
    ajax    @   jquery-1.9.1.js:7978
    RESTDataSource.sync @   MyUtil.js:3820
    sync    @   MyUtil.js:4317
    sync    @   TestDataSource.js:89
    sync    @   MyUtil.js:3407
    fetch   @   MyUtil.js:3236
    processRbaUrl   @   MyUtil.js:13564
    makeRBACall @   ConfigureService.js:587
    initialize  @   ConfigureService.js:570
    initialize  @   CartView.js:31
    wrapper @   MyUtil.js:854
    Backbone.View   @   backbone.js:985
    constructor @   MyUtil.js:11989
    ....

console.log和console.error的一切都是相同的,直到console.error中的 XMLHttpRequest.send(async) ,之后它有比console.log更多的信息。

任何人都可以告诉我为什么会出现这种行为?

0 个答案:

没有答案