Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Platform - Logging with multilines

We are using Node.js server and have logs at Google Cloud Platform.

The problem is, if we do one log entry and we put object inside, which is serialized to multiline output, it is not "stacked".

So if we have object with 100 lines, it creates 100 line ouput into google which is really difficult to read and we are not able to "group" it.

In other services, the output was always stacked (loggly, logsene).

Do you know how to stack input? We are using Winston for logging (which has Console as one of output)

like image 518
libik Avatar asked Mar 22 '17 18:03

libik


2 Answers

Try selecting in stackdriver 'winston_log'.

By default you are receiving the stdout, which gave me the same issues with multilines.

like image 64
GordonHo Avatar answered Sep 24 '22 11:09

GordonHo


This was the solution (PS: thanks to GordonHo to ping me on this question):

const winston = require('winston');
const config = require('config');
const _ = require('lodash');

function transportsMethod() {
    const transports = [];
    if (config.params.oneLineWinston === true) {
        transports.push(new (winston.transports.Console)({
            json: true,
            stringify: (obj) => JSON.stringify(obj),
        }));
    } else {
        transports.push(new (winston.transports.Console)({json: true}));
    }
    return transports;
}

const logger = new winston.Logger({
    level: winstonLevel,
    transports: transportsMethod(),
});

module.exports = logger;
like image 36
libik Avatar answered Sep 25 '22 11:09

libik