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
  • 914
  • 1
  • 20
  • 33

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
  • 11,600
  • 7
  • 43
  • 53