-1

I have been using this logger in node:

// https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
function logC(text) {
  console.log('\x1b[36m%s\x1b[0m', text);
}

However it does not work for multiple arguments. I want to be able to use it like:

logC(text1, text2)

Obviously, I could write out the arguments in the function signature but I was hoping there was a way to do it with the built in arguments.

favor
  • 355
  • 2
  • 13
  • Are you only logging strings or are you trying to completely replicate the `console.log` interface? – Bergi Feb 27 '22 at 04:04
  • So just `console.log('\x1b[36m%s\x1b[0m', Array.from(arguments).join(' '));`? Or use rest parameter syntax. – Bergi Feb 27 '22 at 04:04

1 Answers1

0

I think you are looking for this

function logC(...args) {
  args.forEach((arg) => {
    console.log('\x1b[36m%s\x1b[0m', arg);
  })
}
    
logC('a', 'b', 'cccc', 'dsff') // This gives the output