IE11在控制台中截断字符串

时间:2015-01-08 16:03:16

标签: javascript internet-explorer internet-explorer-11 console.log

我有一个可能是20或30行的字符串,我想在一个console.log调用中输出到控制台。这在Chrome中效果很好,但IE11会截断控制台中大约一半的字符串。有什么办法可以防止这个?字符串类似于:

-----------------------------------------
Wed Jan 7 20:41:16 GMT-0700 2015 530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
-----------------------------------------
41:17:181 - Initiating recording...
41:17:233 - Creating NetStream...
41:17:240 - NetStream created.
41:17:240 - Recording ready.
-----------------------------------------
Wed Jan 7 20:41:16 GMT-0700 2015 NetConnectionQueue - rtmp://AMS2alt.commercialtribe.net/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
-----------------------------------------
41:16:867 - Initializing...
41:16:868 - Creating negotiator...
41:17:175 - Connection success: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:175 - Connection added to queue.
41:17:182 - Connection request recieved...
41:17:183 - Connection request fulfilled.
41:17:452 - Connection success: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:452 - Connection added to queue.
41:18:503 - -----------------------------------------
Wed Jan 7 20:41:16 GMT-0700 2015 NetNegotiator Log
-----------------------------------------
41:16:890 - Attempting: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:174 - Negotiator reset
41:17:194 - Attempting: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:282 - Attempting: rtmp://AMS2alt.commercialtribe.net:443/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:339 - Attempting: rtmp://AMS2alt.commercialtribe.net:80/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:400 - Attempting: rtmpt://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:451 - NetConnection attempt failed: rtmp://AMS2alt.commercialtribe.net:443/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9
41:17:452 - Negotiator reset

4 个答案:

答案 0 :(得分:15)

单个邮件的1024个字符限制并非完全不合理。即便如此,IE也无法改变这种限制。

出于好奇,为什么这是一个大块,而不是与console.log()分组的console.group()个人电话?



console.group("Wed Jan 7 20:41:16 GMT-0700 2015 530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:181 - Initiating recording...");
console.log("41:17:233 - Creating NetStream...");
console.log("41:17:240 - NetStream created.");
console.log("41:17:240 - Recording ready.");
console.groupEnd();
console.group("Wed Jan 7 20:41:16 GMT-0700 2015 NetConnectionQueue - rtmp://AMS2alt.commercialtribe.net/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:16:867 - Initializing...");
console.log("41:16:868 - Creating negotiator...");
console.log("41:17:175 - Connection success: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:175 - Connection added to queue.");
console.log("41:17:182 - Connection request recieved...");
console.log("41:17:183 - Connection request fulfilled.");
console.log("41:17:452 - Connection success: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:452 - Connection added to queue.");
console.groupEnd();
console.group("Wed Jan 7 20:41:16 GMT-0700 2015 NetNegotiator Log");
console.log("41:16:890 - Attempting: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:174 - Negotiator reset");
console.log("41:17:194 - Attempting: rtmp://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:282 - Attempting: rtmp://AMS2alt.commercialtribe.net:443/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:339 - Attempting: rtmp://AMS2alt.commercialtribe.net:80/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:400 - Attempting: rtmpt://AMS2alt.commercialtribe.net:1935/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:451 - NetConnection attempt failed: rtmp://AMS2alt.commercialtribe.net:443/recorder/530d8aa855df0c2d269a5a5853a47a049c52c9d83a2d71d9");
console.log("41:17:452 - Negotiator reset");
console.groupEnd();




如果邮件是作为一个大字符串收到的,你当然可以解析它并单独记录每一行,即:

 msg.split("\n").forEach(function(line) { console.log(line); }); // *real* parser pending

答案 1 :(得分:6)

我知道这是一个老问题,但只是发布以防万一找到它的人。

如果您喜欢我,并且只是想确保您将所有正确的数据转换为字符串以进行简单测试,那么您可以执行类似的操作。也许有点复杂但有用的时候我需要检查的长字符串是否正确形成并且具有正确的内容。 你肯定可以将它与接受的(佳能)答案中提到的 console.group()配对。



var str=""; // string with length greater than 1024 characters

var plngth = 1024; // number of characters to print per console.log
var limit = Math.floor(str.length / plngth);
for (var k = 0; k < limit+1; k++) {
  if (k == limit)
      console.log(str.substring(plngth * k, str.length-1));
  else
      console.log(str.substring(plngth*k,plngth*(k+1)-1));
}
&#13;
&#13;
&#13;

答案 2 :(得分:2)

如果您要记录的文本没有分成行,或者行可能超过限制,您可以使用这个简单的函数来“格式化”日志输出:

function logMessage(title, message) {
    // make sure if the 'console' object and its methods are available,
    // to avoid issues, like your JS code is broken by logging.
    // see: https://stackoverflow.com/a/7742862/704022
    if (console && console.log && console.group && console.groupEnd) {
        var maxLength = 10; // set to 10 to enable easier testing, should be 1024
        console.group(title);
        for (var pos = 0; pos < message.length ; pos += maxLength) {
            console.log(message.substring(pos, pos + maxLength));
        }
        console.groupEnd();
    }
}

logMessage("Test", "0123456789012345678901234");

答案 3 :(得分:0)

phoppar:您是正确的。我看到多个群组消息的结果不一致,并认为缺少的参数可以解决此问题(后来发现它不能解决)。这仅在IE11中发生,并且似乎是IE固有的竞争条件。如果我在两次消息记录之间设置100ms的延迟,则该问题将永远不会发生。

有一个groupEnd引用,该参数具有该参数,但似乎与IE隔离,而且我还没有发现使用它会有所作为的任何情况。 https://technet.microsoft.com/en-us/dn265070(v=vs.80)