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

0 Answers