Esm: usage of esm with google cloud functions prevents console.log(error, warn) to occur in stackdriver logs

Created on 13 Dec 2018  路  5Comments  路  Source: standard-things/esm

version: "esm": "^3.0.84"

Every console.log in google cloud functions logged and visible inside google cloud stackdriver logs
but with esm it's not working. No console.log, console.error etc are now visible inside stackdriver

Is it possible to make it work? Is any options to not redefine native console.log?
(For now I redefined global.dConsole = console; and dConsole.log etc works)

_Seems like same issue with console as was in electron and inspector_

steps to reproduce:

index.js

global.dConsole = console;
const { routes } = require('esm')(module)('./routes');

module.exports.scraper = (req, res) => {
  if (!req.path)
    req.url = `/${req.url}`;
  return routes(req, res);
};

routes.js

import express from 'express';
const app = express();

app.use('/getStatus', async (req, res) => {
  dConsole.log('dConsole hello');
  console.log('console hello');
  res.send('hello');
});

export const routes = app;

deploy on gcloud:

gcloud functions deploy scraper  --entry-point=scraper --project=blabla-project --trigger-http --region=europe-west1 --runtime nodejs8

open in browser:

https://europe-west1-blabla-project.cloudfunctions.net/scraper/getStatus

see logs

dConsole hello

must be in logs

dConsole hello
console hello

Some specific env variables for cloud fuctions if it's needed to detect that code is runned inside:

 "X_GOOGLE_FUNCTION_TIMEOUT_SEC": "60",
 "X_GOOGLE_FUNCTION_MEMORY_MB": "2048",
 "FUNCTION_TIMEOUT_SEC": "60",
 "X_GOOGLE_LOAD_ON_START": "false",
 "X_GOOGLE_FUNCTION_NAME": "blabla",
 "FUNCTION_TRIGGER_TYPE": "HTTP_TRIGGER",
 "X_GOOGLE_GCLOUD_PROJECT": "blabla",
 "FUNCTION_NAME": "bla",
 "X_GOOGLE_GCP_PROJECT": "blabla",
 "X_GOOGLE_FUNCTION_REGION": "europe-west1",
 "X_GOOGLE_ENTRY_POINT": "app",
 "FUNCTION_REGION": "europe-west1",
 "X_GOOGLE_WORKER_PORT": "8091",
 "X_GOOGLE_FUNCTION_IDENTITY": "balbla",
 "GCLOUD_PROJECT": "blabla",
 "X_GOOGLE_CODE_LOCATION": "/srv",
 "FUNCTION_IDENTITY": "blabla",
 "GCP_PROJECT": "blabla",
 "X_GOOGLE_FUNCTION_VERSION": "167",
 "X_GOOGLE_SUPERVISOR_INTERNAL_PORT": "8081",
 "X_GOOGLE_NEW_FUNCTION_SIGNATURE": "true"
question

Most helpful comment

Thank you again, here is the example project https://github.com/istarkov/esm-log-issue-example
I've sent you invitation to gcloud.

One issue I havent found a way how to prevent cloud function to override node_modules folder so I placed esm folder from node_modules in sources and require it via relative path

All 5 comments

Hi @istarkov!

I've done a lot of work to console in the upcoming release. If you could create a simple repo I can checkout I could check if it has fixed the issue you're seeing. Does deploying copy the local node_modules folder (so I can just replace the esm build with one from master)?

Thank you!, Ill create at morning repo, gcloud project, and write all steps needed to deploy it with node_modules.

Thank you again, here is the example project https://github.com/istarkov/esm-log-issue-example
I've sent you invitation to gcloud.

One issue I havent found a way how to prevent cloud function to override node_modules folder so I placed esm folder from node_modules in sources and require it via relative path

Wow thank you @istarkov for making this soo easy to setup and test. It looks like with our master branch build the output is as expected

D esm-log 67t8jot61r2r 2018-12-13 17:35:36.872 Function execution started
I esm-log 67t8jot61r2r 2018-12-13 17:35:36.884 111 a non esm hello
I esm-log 67t8jot61r2r 2018-12-13 17:35:36.888 console log in module wrapped with esm
D esm-log 67t8jot61r2r 2018-12-13 17:35:36.892 Function execution took 21 ms, finished with status code: 200

Super, Thank you!!!!!
Waiting for the new release.
Can't say how much this library made my life easier!!!

Was this page helpful?
0 / 5 - 0 ratings