0

I am working in a NodeJS app built using Express.

Logs from several files, and from libraries log fine, but many of them, including from libraries I have no control, have some sort of line break in them.

My goal is to have a single line of logging without the line breaks.

for example:

var a = 'var a';
var b = 'var b';
var c = 'var c';

console.log({ a, b, c });

Instead of seeing those in separate lines I would like to have them in a single line.

Is it possible to somehow intercept globally the call, and remove all line breaks?

Could I do that in logstash, or some other facility?

Filipe Miranda
  • 874
  • 15
  • 32

1 Answers1

0

The core util module has util.format that can do the job, if the data is simple enough.

const util = require('util');

var a = 'var a';
var b = 'var b';
var c = 'var c';

console.log({ a, b, c });

console.log(util.format(a, b, c));
Matthew Bakaitis
  • 10,965
  • 6
  • 41
  • 52