I'm using Google Cloud Functions and the module @google-cloud/logging-winston.
My first issue is when using this module the property
labels: {
execution_id: "idHere"
}
is not in the Stackdriver logs, like it is when I use the regular console.log(''); is it possible to get that execution_id back into the logs?
Also, can I add custom labels to a log, for instance a user ID. I'm trying to make my logging process easier for myself so I can see the flow for each API endpoint request via execution_id and also be able to see all logs by a certain user via adding a user ID label.
My current logging code is
'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));
}