Stackdriver execution_id和自定义标签

时间:2018-02-15 12:24:20

标签: logging google-cloud-platform google-cloud-functions stackdriver

我正在使用Google Cloud Functions和模块@ google-cloud / logging-winston。

我的第一个问题是使用此模块属性

labels: {
  execution_id: "idHere"
}

不在Stackdriver日志中,就像我使用常规console.log时一样('');是否有可能将execution_id恢复到日志中?

此外,我可以向日志添加自定义标签,例如用户ID。我试图让自己的日志记录过程更容易,因此我可以通过execution_id查看每个API端点请求的流量,并且还可以通过添加用户ID标签查看特定用户的所有日志。

我当前的日志记录代码是

'use strict'

import * as winston from 'winston';
const Logger = winston.Logger;
const Console = winston.transports.Console;

import { LoggingWinston } from '@google-cloud/logging-winston'
const loggingWinston = new LoggingWinston();

const logger = new Logger({
    level: 'debug', // log at 'debug' and above
    transports: [
        // Log to the console
        new Console(),
        // And log to Stackdriver Logging
        loggingWinston,
    ],
});

function formatMessage(message) {
    return message;
};

export const error = (message) => {
    logger.error(formatMessage(message));
}
export const warn = (message) => {
    logger.warn(formatMessage(message));
}
export const verbose = (message) => {
    logger.verbose(formatMessage(message));
}
export const info = (message) => {
    logger.info(formatMessage(message));
}
export const debug = (message) => {
    logger.debug(formatMessage(message));
}

0 个答案:

没有答案