本文介绍了Firebase功能:在堆栈驱动程序控制台中使用Winston进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使 winston 记录器将日志写入堆栈驱动程序控制台.我将我的函数部署为google firebase函数(使用 firebase deploy
). console
日志记录可以很好地工作,但是我们在项目中不使用这种工具.
I cannot make winston logger to write logs to stackdriver console. I deploy my functions as google firebase functions (using firebase deploy
). console
logging works fine, but we don't use such tool in the project.
我尝试过的事情:
- 使用 https://github.com/greglearns/winston-stderr 输出到stderr
- 使用 https://www.npmjs.com/package/@ google-cloud/logging-winston (都为
winston.add(require('@google-cloud/logging-winston')); winston.log('error', 'Winston error!');
,还添加了诸如项目IDprojectId
/服务帐户JSON凭证文件keyFilename
之类的参数); - 使用> https://github.com/findanyemail/winston-transport- stackdriver-error-reporting .也没有运气.我仍然看不到堆栈驱动程序中的日志.
- output to stderr using https://github.com/greglearns/winston-stderr
- using https://www.npmjs.com/package/@google-cloud/logging-winston (both
winston.add(require('@google-cloud/logging-winston')); winston.log('error', 'Winston error!');
and also adding with parameters such as project IDprojectId
/ service account JSON credentials filekeyFilename
); - using https://github.com/findanyemail/winston-transport-stackdriver-error-reporting . Also no luck. I still cannot see logs in stackdriver.
请建议...我已经厌倦了实验(每次重新部署都需要时间)
Please suggest... I'm tired of experiments (each re-deploy takes time)
推荐答案
最后我做了什么-实现了自定义交通工具,实际上是在引擎盖下调用console.log
.这有帮助.
Finally what I did - implemented custom transport which actually calls console.log
under the hood. This helped.
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);
};
这篇关于Firebase功能:在堆栈驱动程序控制台中使用Winston进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!