如何使用堆栈驱动程序日志记录NodeJS lib @ google-cloud / logging记录堆栈驱动程序条目

时间:2020-02-08 13:34:59

标签: node.js jasmine google-cloud-logging

我正在使用带有Jasmine的量角器,在其中集成了stackdriver lib @ google-cloud / logging。当我运行这个库时,我得到entryId,但是在stackdriver中没有看到日志。我调试了这些问题,并且似乎在异步等待概念中遇到了一些问题:

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}`);
};

在这里的任何帮助将不胜感激!

0 个答案:

没有答案