Node.js Firebase功能:在stackdriver控制台中使用winston登录
我无法使记录器将日志写入控制台。我将函数部署为google firebase函数(使用)<代码>控制台日志记录工作正常,但我们在项目中不使用这种工具 我尝试的是: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)等参数进行添加 使用。也没有运气。
- 使用
- 使用(包括
,并使用项目IDwinston.add(require('@google cloud/logging winston'));winston.log('error','winston error!');
/service account JSON凭证文件projectId
)等参数进行添加李>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中用作要点?