Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Firebase功能:在stackdriver控制台中使用winston登录_Node.js_Google App Engine_Firebase_Logging_Winston - Fatal编程技术网

Node.js Firebase功能:在stackdriver控制台中使用winston登录

Node.js Firebase功能:在stackdriver控制台中使用winston登录,node.js,google-app-engine,firebase,logging,winston,Node.js,Google App Engine,Firebase,Logging,Winston,我无法使记录器将日志写入控制台。我将函数部署为google firebase函数(使用)控制台日志记录工作正常,但我们在项目中不使用这种工具 我尝试的是: 使用 使用(包括winston.add(require('@google cloud/logging winston'));winston.log('error','winston error!');,并使用项目IDprojectId/service account JSON凭证文件keyFilename)等参数进行添加 使用。也没有运气。

我无法使记录器将日志写入控制台。我将函数部署为google firebase函数(使用)<代码>控制台日志记录工作正常,但我们在项目中不使用这种工具

我尝试的是:

  • 使用
  • 使用(包括
    winston.add(require('@google cloud/logging winston'));winston.log('error','winston error!');
    ,并使用项目ID
    projectId
    /service account JSON凭证文件
    keyFilename
    )等参数进行添加
  • 使用。也没有运气。我仍然无法在stackdriver中看到日志

请建议。。。我厌倦了实验(每次重新部署都需要时间)

最后我做了什么-实现了它,它实际上在引擎盖下调用了
console.log
。这有帮助

const winston = require('winston');
const util = require('util');
const ClassicConsoleLoggerTransport = winston.transports.CustomLogger = function (options) {
    options = options || {};
    this.name = 'ClassicConsoleLoggerTransport';
    this.level = options.level || 'info';
    // Configure your storage backing as you see fit
};
util.inherits(ClassicConsoleLoggerTransport, winston.Transport);

ClassicConsoleLoggerTransport.prototype.log = function (level, msg, meta, callback) {
    let args = [msg, '---', meta];
    switch (level) {
        case 'verbose':
        case 'debug':
            console.log.apply(null, args);
            break;
        case 'notice':
        case 'info':
            console.info.apply(null, args);
            break;
        case 'warn':
        case 'warning':
            console.warn.apply(null, args);
            break;
        case 'error':
        case 'crit':
        case 'alert':
        case 'emerg':
            console.error.apply(null, args);
            break;
        default:
            console.log.apply(null, args);
    }
    callback(null, true);
};

Winston的默认控制台传输失败,因为它在可用时使用
控制台。_stdout.write
,这是Firebase函数不接受的


现在有一个你可以试试的方法。没有使用过它,如果使用Winston 3,它需要节点
^8.11.2

能否添加所需文件以及如何在github中用作要点?