Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Logging in Functions

I've set up an Angular SSR on a Firebase function. Now I try to debug a few things, but something I'm missing.

I've imported the functions

import functions from 'firebase-functions';

 and try to use them in my Express calls

server.get('*', (req, res) => {
    const hostUrl = `${req.protocol}://${req.get('Host')}`;
    const userAgent = req.header('User-Agent');

    // Leveraging PWA if not a robot
    if (isbot(userAgent)) {
      functions.logger.debug(`Using SSR on user agent ${userAgent}`);
      res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }, {provide: HOST_URL, useValue: hostUrl}] });
    } else {
      functions.logger.debug(`Using PWA on user agent ${userAgent}`);
      res.sendFile(join(distFolder, 'index.html'));
    }
  });

 If not done everything wrong I should log these messages. But if looking at Log Explorer of GCP I cannot see my log entries. Am I looking at the wrong place or what is my mistake?

Solved Solved
0 4 2,721
1 ACCEPTED SOLUTION

Hi, tomoh,

Thanks for answering.

Did you link Cloud Logging for Firebase as well? Please refer to the documentation to link the Cloud Logging to the Firebase.

Looking forward to your response.

View solution in original post

4 REPLIES 4

Hi, tomoh,

It might be that the Cloud Logging API is not enabled.

To enable the Cloud Logging API, please follow the steps below:
Go to the GCP Console of your project. From the navigation menu, go to API and services. Go to Libraries, and search for Cloud Logging API. Select the Cloud Logging API. Click on enable.

You can refer to documentation on how to enable the Cloud Logging API.

Please try checking the stdout logs in the Cloud Logging/Logs explorer after enabling the API. You can refer to documentation for more information regarding Cloud Logging API and how the API performs logging-related tasks, including reading and writing log entries, creating log-based metrics, and managing sinks to route logs.

Looking forward to your response.

No, the API is activated.

Hi, tomoh,

Thanks for answering.

Did you link Cloud Logging for Firebase as well? Please refer to the documentation to link the Cloud Logging to the Firebase.

Looking forward to your response.

Ah, no I didn't. Thanks for the hint. I haven't any need for logging at the moment, but I'm pretty sure that was my issue. Thank you!

Top Solution Authors