最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Cloud Platform - Logging with multilines - Stack Overflow

programmeradmin1浏览0评论

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)

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)

Share Improve this question asked Mar 22, 2017 at 18:02 libiklibik 23k10 gold badges51 silver badges92 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Try selecting in stackdriver 'winston_log'.

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

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;
发布评论

评论列表(0)

  1. 暂无评论