how to break console.log maximum characters limit
hi, im using usual
deno run file.ts
command and realized that there is a limit to number characters that shown on console.log on my terminal(which is 100 characters), is there any workaround related to this?10 Replies
I wasn't able to find the answer to your question in the official Deno documentation. Deno typically does not impose a limit on the number of characters that can be logged to the console; it's possible that the limit you're encountering is due to your terminal settings rather than Deno itself.
However, based on the information you've provided, there are no obvious syntax errors or mistakes in your message. If you're experiencing a character limit, it might be worth checking your terminal settings or looking into whether any environment variables or configurations could be affecting the output of
console.log
.
Please note that this advice is not based on the Deno documentation, and I would recommend double-checking the accuracy of this advice and exploring your terminal or shell documentation for more information on handling long lines of output.There's no limit
If you are printing an object, maybe the object itself is truncating its textual representation, not
console.log
See: https://deno.land/api@v1.40.5?s=Deno.inspectDeno
Deno.inspect | Runtime APIs | Deno
Converts the input into a string that has the same format as printed by
console.log()
.Console.log does abbreviate very long objects. Strings will never be abbreviated. If you want more control on how to print objects, you can explicitly convert your stuff to string, using for example JSON.stringify with parameters of your choice, eg.
console.log(JSON.stringify(obj, null, 2))
There exists an open issue and/or a PR to increase the amount of characters printed by default by console.log([object])
to 10000, but afaik it hasn't been merged in yet. (personally I hope it won't be merged either, as I like the current default behaviour, but whatever 🤷 )Oh I thought the limit was implemented inside
Deno.inspect
, not in console.log
thanks @Leokuma @raunioroo
strings always get abbreviated in Deno tho
I meant direct string arguments to console.log. Strings inside objects, arrays etc yeah thats different
It is a direct string argument tho
Notice the
.join
at the end
I just wanted a long string and couldn't bother holding the a
for long
Okay so the problem isn't with console.log
Nvm
It was the repl cutting the text offOhh. Yeah, didn't notice the
join()
. Weird, but as you said maybe it's the repl. I do a lot of IPC by just console.logging
lines of JSON.stringified
data to the parent process, and have never run into problems. The outputs can get occasionally large. If console.log did anything weird to those outputs, I'd have noticed if the outputs were not parseable as lines of JSONI use the repl to quickly convert some text into JSON so it was pretty annoying that I always had to write the output to a file or use console.log
(And I just realized that I could've used console.log)