3

I am using protractor having Jasmine where I intergrated stackdriver lib @google-cloud/logging. When I run this lib, I get entryId however I dont see logs in stackdriver. I debug the issues and seems like some issues with async-await concepts:

jasmine.getEnv().addReporter({
    specDone: function (result) {
        if(result.failedExpectations.length){
            count++;
        }
    },
    suiteDone: function (result) {
        console.log(count);
        if (count!=0) {
            (async() => {
                console.log('1')
                await stackdriverLogEntry("Your GCP project", "protractor-log-data", "success: false");  
                console.log('2')
              })()
        } else { 
            (async() => {
                console.log('3')
                await stackdriverLogEntry("Your GCP project", "protractor-log-data", "success: true");  
                console.log('4')
              })()
        };
    }
})


---------------------------------------------------------------------------

this.stackdriverLogEntry = async function (projectId, logName, text) {
    // Creates a client
    const logging = new Logging({ projectId: projectId });
    // Selects the log to write to
    const log = logging.log(logName);
    // The metadata associated with the entry
    const metadata = {
        resource: { type: 'global' },
    };
    // Prepares a log entry
    const entry = log.entry(metadata, text);
    console.log(JSON.stringify(entry));
    // Writes the log entry
    await log.write(entry);
    console.log(`metadata: ${JSON.stringify(metadata)}`);
    console.log(`Logged: ${text}`);
};

Any HELP here would be appreciated!!!

Swatantra Kumar
  • 1,324
  • 5
  • 24
  • 32
Gaurav
  • 31
  • 3
  • Have you taken a loot to [this documentation](https://cloud.google.com/logging/docs/setup/nodejs) which explains how to set Stackdriver logging with Node? Also, where are you deploying this application? Make sure that you are looking for the logs in the correct resource – rsalinas Feb 10 '20 at 10:01
  • Issue is not with the logging lib but with async and await. I want to have a calling function as sync and then called function as async having await function. Here, calling function is jasmine reporter, called and await functions are from logging library. I checked with setTimeOut() as well but no luck. For now, I have taken other approach to push stackdriver logs :) Cheers! – Gaurav Feb 10 '20 at 17:48
  • Sorry, code is perfect however there is an issue with this node lib. Was able to see similar issue using this lib with other approaches as well. – Gaurav Feb 21 '20 at 06:02

0 Answers0