Here is my log, print by `console.log`. 

```
2019-05-07T07:28:44.246Z[error]: {
  "message": "Unexpected end of JSON input",
  "service": "better-logging",
  "timestamp": "2019-05-07T07:28:44.246Z",
  "stack": "SyntaxError: Unexpected end of JSON input\n    at JSON.parse (<anonymous>)\n    at Object.findById (/Users/ldu020/workspace/github.com/mrdulin/nodejs-gcp/src/stackdriver/better-logging/logger.spec.js:18:12)\n    at Object.findById (/Users/ldu020/workspace/github.com/mrdulin/nodejs-gcp/src/stackdriver/better-logging/logger.spec.js:8:15)\n    at Object.<anonymous> (/Users/ldu020/workspace/github.com/mrdulin/nodejs-gcp/src/stackdriver/better-logging/logger.spec.js:27:15)\n    at Module._compile (module.js:652:30)\n    at Object.Module._extensions..js (module.js:663:10)\n    at Module.load (module.js:565:32)\n    at tryModuleLoad (module.js:505:12)\n    at Function.Module._load (module.js:497:3)\n    at Function.Module.runMain (module.js:693:10)"
}

```

As you can see, the value of the `stack` field has many newline symbols `\n`

I want to print the `stack` with correct indent:

```
"SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.findById (/Users/ldu020/workspace/github.com/mrdulin/nodejs-gcp/src/stackdriver/better-logging/logger.spec.js:18:12)
    at Object.findById (/Users/ldu020/workspace/github.com/mrdulin/nodejs-gcp/src/stackdriver/better-logging/logger.spec.js:8:15)
    at Object.<anonymous> (/Users/ldu020/workspace/github.com/mrdulin/nodejs-gcp/src/stackdriver/better-logging/logger.spec.js:27:15)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)"

```

It's weird that I copy the string into `console` of chrome browser, then the format is correct.

**NOTE:** The output is already printed by `console.log` method. And, I can't call `console.log` again. I can get the value of `stack`, so I need some formatting code to handle the string.

**Update:**

I use `winston` logger module. Here is my config: 

```
const printf = format.printf((info) => {
    const { level, ...rest } = info;
    let log;
    if (rest.stack) {
      //rest.stack = rest.stack.split('\n').map((line) => {
       // return line.trim();
      //});
      log = rest;
    }
    log = JSON.stringify(rest, null, 2);
    return `${info.timestamp}[${info.level}]: ${log}`;
  });
  transports = [
    new winston.transports.Console({
      format: format.combine(format.colorize(), format.timestamp(), format.errors({ stack: true }), printf)
    })
  ];

```