4

Currently, both console.log and console.dir truncate their output. Here's a pull request that explicitly limited, by default, the size of the console output for the NativeScript Android runtime. I couldn't find a similar pull request for the iOS runtime. The pull request for Android added a configuration option that can be set to change the limit but no such option seems to exist for iOS.

Here's a (closed) issue for the main NativeScript project with a comment mentioning that no configuration option seems to be available (or at least known) to change the apparent limit:

I checked the NativeScript, NativeScript iOS runtime, and even WebKit sources (on which the NativeScript iOS runtime depends for its JavaScript runtime from what I could tell) and I couldn't find any obvious limit on the size of console messages.

In the interim, I've opted to use this function in my code:

function logBigStringToConsole(string) {
  const maxConsoleStringLength = 900; // The actual max length isn't clear.

  const length = string.length;

  if (length < maxConsoleStringLength) {
    console.log(string);
  } else {
    console.log(string.substring(0, maxConsoleStringLength));
    logBigStringToConsole(string.substring(maxConsoleStringLength));
  }
}

and I use it like this:

logBigStringToConsole(JSON.stringify(bigObject));
Kenny Evitt
  • 9,291
  • 5
  • 65
  • 93
  • You are the best Kenny !! that function helpme to log. – moralejaSinCuentoNiProverbio Oct 07 '20 at 12:46
  • 1
    I hit circular structure error, i wish to direct log an EventData on user tapping it, but JSON cannot stringify a circular structured data – elliotching May 12 '21 at 09:29
  • @elliotching [That's a separate question :)](https://stackoverflow.com/questions/11616630/how-can-i-print-a-circular-structure-in-a-json-like-format) But you might want to combine the interim solution to this one with an answer to the other for your case. – Kenny Evitt May 12 '21 at 14:24

0 Answers0