Is there a Node.js console.log length limit?

后端 未结 2 988
野性不改
野性不改 2021-02-14 17:03

Is there a limit the length of console.log output in Node.js? The following prints numbers up to 56462, then stops. This came up because we were returning datasets from MySQL

相关标签:
2条回答
  • 2021-02-14 17:35

    I would recommend using output to file when using node > 6.0

    const output = fs.createWriteStream('./stdout.log');
    const errorOutput = fs.createWriteStream('./stderr.log');
    // custom simple logger
    const logger = new Console(output, errorOutput);
    // use it like console
    var count = 5;
    logger.log('count: %d', count);
    // in stdout.log: count 5
    
    0 讨论(0)
  • 2021-02-14 17:37

    Have you tried writing that much on a machine with more memory?
    According to Node source code console is writing into a stream: https://github.com/joyent/node/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/console.js#L55
    And streams may buffer the data into memory: http://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback

    So if you put reeeaally a lot of data into a stream, you may hit the memory ceiling. I'd recommend you split up your data and feed it into process.stdout.write method, here's an example: http://nodejs.org/api/stream.html#stream_event_drain

    0 讨论(0)
提交回复
热议问题