0

Inside the backquote, if I start a new line, the printed string will start a new line as well.

e.g.

  winston.format.printf(
    (info) => `${info.timestamp}  ${os.hostname()} ${process.pid} ${info.level}: ${info.message}`,
  ),

will print

2021-Nov-30 01:27:39:2739  MacBook-Pro.local 56939 info: initializeExpress() COMPLETED

But

  winston.format.printf(
    (info) => `${info.timestamp}  ${os.hostname()} 
               ${process.pid} ${info.level}: ${info.message}`,
  ),

will print:

2021-Nov-30 01:27:39:2739  MacBook-Pro.local
    56939 info: initializeExpress() COMPLETED

I had to start a new line in the code because of code specification. But I need to avoid starting a new line in the log message.

How?

Kid_Learning_C
  • 2,605
  • 4
  • 39
  • 71
  • 1
    Does this answer your question? [Wrap long template literal line to multiline without creating a new line in the string](https://stackoverflow.com/questions/37321047/wrap-long-template-literal-line-to-multiline-without-creating-a-new-line-in-the) – aerial Nov 29 '21 at 16:35

1 Answers1

1

End the template literal at the end of the first line, and concatenate with the next with +.

  winston.format.printf(
    (info) => `${info.timestamp}  ${os.hostname()} ` +
              `${process.pid} ${info.level}: ${info.message}`,
  ),

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320