0

console.log(and related functions) can output given params to console

Besides simple string param, console.log can accept object list and format string:

console.log(obj1 [, obj2, ..., objN);
console.log(msg [, subst1, ..., substN);

I want to know if there is a simple way to get the string representation of the params given to console.log, in other words, I just want to get the string representation that console.log output.

diff from the question: "How to get the console.log content as string in JavaScript" is, the answer seems can not handle format string and I want to get the string output of console.log which is different from the implementation of printf.

tkokof
  • 101
  • 1
  • 9
  • [JavaScript equivalent to printf/String.Format](https://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format) ? – Andreas Jul 04 '19 at 12:01
  • please see quotes above – tkokof Jul 04 '19 at 12:19
  • https://stackoverflow.com/questions/24052775/how-to-get-the-console-log-content-as-string-in-javascript RETURN ERROR – Mister Jojo Jul 04 '19 at 12:22
  • something like that : `function _private_log() { for(let arg of arguments) console.log( JSON.stringify(arg) ) };` – Mister Jojo Jul 04 '19 at 12:25
  • so you means applying JSON.stringify to every arguments and join them together ? for format string, I need to implement printf-like functions ? Seems this will work but it is a little bit complex ... I wonder if there is a better and clear way to do this ... – tkokof Jul 05 '19 at 03:02

0 Answers0