Google Cloud Platform - Logging with Multi-Line

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

The problem is that if we do one log entry and we put an object inside that is serialized for multi-line output, it doesn't "fit".

So, if we have an object with 100 lines, it creates 100 lines on google, which is really hard to read and we cannot "group" it.

In other services, the output was always pushed onto the stack (loggly, logsene).

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

+3


source to share


2 answers


This was the solution (PS: thanks to GordonHo for telling me about this issue):



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;

      

+1


source


Try selecting 'stackdriver' in windon_log.



You get stdout by default, which gave me the same problems with multi-lines.

+2


source







All Articles