Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

console.log limitation

Is there a setting to increase the line length for the console.log?

 

The first instruction prints 106 characters to the log

The second instruction is ignored [nothing appears in the log]

 

console.log("123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456");

 

console.log("123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567");

 

Shown here in case anyone runs into this problem, of messages not appearing in the log.

Author | ch, passion for improvement.

Best Answer
0 Votes
15 REPLIES 15

It works for me (in Fitbit Studio)

capture.png

 

 

Best Answer
0 Votes

Thanks @kozm0naut , on a Sense in Fitbit Studio?

Author | ch, passion for improvement.

Best Answer
0 Votes

On a Versa 3 in Fitbit Studio

Best Answer
0 Votes

@kozm0naut- tested it again, it doesn't work, for Sense, Versa 3, App or Clock face, SDK 6.0 or 6,1

but works for Versa 2 SDK 4.3 App

 

Totally weird, there must be a parameter which controls line length.

 

Logged out of simulator 0.9.4 and back in and Studio on Firefox.

Author | ch, passion for improvement.

Best Answer
0 Votes

I've experienced this often. I suspect that the dev bridge or comms connection gets flooded so it silently drops lines (especially long lines) to keep up.

I don't know of any way to change this behaviour. My only workaround is to output stuff less frequently or more briefly.

 

I think there's a third-party module that lets you log to a file/server for later access.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Perhaps you could craft a utility function that checks the string length and over a certain length, breaks it up as needed and spits them out on a timeout of 1ms or something.

Best Answer

@kozm0naut Wow, that's a good idea! I might have a go at that.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana  - it's not a timing issue as reversing the 2 instructions produces the same error, so it is a line length issue, in which it doesn't even attempt to display anything at all.

 

You would think it would just display the text it can rather than ignore the instruction completely.

 

Merely switching between Versa 3 and Versa 2 gets different results, it works in the latter.

Author | ch, passion for improvement.

Best Answer
0 Votes

I think it's both things. If you try to spit out more than about 30 lines in quick succession, you'll start to miss some lines.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana- it's definitely not a timing issue in this case as running one or other of the instructions works or doesn't, consistently.

 

It seems like a bug or corruption with Simulator 0.9.4

 

Tried on a different PC with the older Simulator 0.9.2 and it works correctly.

 

@kozm0naut- can you confirm which version of simulator you tried with, that works for you?

Author | ch, passion for improvement.

Best Answer
0 Votes

I'm not using the simulator, I am using an actual Versa 3.

Best Answer
0 Votes

Thanks @kozm0naut - it would seem to confirm a bug with the Simulator.

Author | ch, passion for improvement.

Best Answer
0 Votes

This was a fun diversion for a Sunday afternoon.

index.js:

import './console-queue'

console.enqueue('This is a very long line of text that may not be displayed by console.log(), which seems to be limited to a maximum message length of 105 characters.')

for (let i=0; i<100; i++)
  console.enqueue(`The next value in the sequence is ${i}`)

 console-queue.js:

const LOG_PERIOD = 10           // ms between console.log() calls; change this as required
const MAX_LENGTH = 65           // maximum length of a string to be passed to console.log() (105 max); 65 avoids most ugly wrapping
const queue = []                // enqueued strings to log
let timer                       // setTimeout id

console.enqueue = message => {  // adding members to a built-in object is probably a bit naughty
  // This function makes no attempt to check for memory exhaustion.
  // It may be possible to append to a file to allow for a longer log queue, but writing to a file may not be faster than writing to console.

  // It's possible to get the minified line number of the enqueue() function call using: (new Error()).stack
  // ...but since minified line numbers don't match source code, they're not particularly useful.
  // Recommended workaround is to put an identifying tag string at the start of each message; eg, enqueue(`myFunc x=${x}`)

  if (message.length <= MAX_LENGTH) {   // whole message will fit in one line
    queue.push(message)
  } else {                              // message is too long for one line, so break it up
    // enqueue first line:
    queue.push(message.substring(0, MAX_LENGTH - 1) + '\\')
    message = message.substring(MAX_LENGTH - 1)

    // enqueue intermediate lines:
    while (message.length > MAX_LENGTH - 3) {                         // last line can contain MAX_LENGTH-3 characters
      queue.push('  \\' + message.substring(0, MAX_LENGTH - 4) + '\\')  // starting and ending ellipsis strings total 4 chars
      message = message.substring(MAX_LENGTH - 4)
    }

    // enqueue last line:
    queue.push('  \\' + message)
  }

  if (timer === undefined) timer = setTimeout(processQueue, LOG_PERIOD)
}

function processQueue() {
  console.log(queue.shift())

  if (queue.length)     // the queue still has stuff in it
    timer = setTimeout(processQueue, LOG_PERIOD)
  else
    timer = undefined   // so that console.enqueue() knows to restart it
}

If, in index.js, you replace the calls to console.enqueue with console.log, the long line will probably disappear and the incrementing lines will probably skip some values.

Seems to work on current sim (Versa 3); not tested on hardware or Studio.

Peter McLennan
Gondwana Software
Best Answer

@Gondwana Very cool, I had been thinking a queue is probably the real best solution so the lines don't get out of order. Nice work!

Best Answer

@kozm0nautThanks! 😁 Lines can still get out of order if mixing .log and .enqueue. I was tempted to try to replace .log with .enqueue, but thought that might have been going a bit far.

Peter McLennan
Gondwana Software
Best Answer
0 Votes