Midway v2.11.2 发布,提供 Serverless 日志库支持

栏目: 软件资讯 · 发布时间: 4年前

内容简介:增强 1、@midwayjs/logger 日志库支持多参数输出 由于之前 @midwayjs/logger 的日志对接了 winston3,由于 winston 的入参限制,无法支持多个参数。 比如: logger.info('123', '456', '789'); 对于 winston ...

增强

1、@midwayjs/logger 日志库支持多参数输出

由于之前 @midwayjs/logger 的日志对接了 winston3,由于 winston 的入参限制,无法支持多个参数。

比如:

logger.info('123', '456', '789');

对于 winston 来说,只会识别第一个字符串,midway 在其之上做了调整和优化,使其能支持最多 2 个参数。

在新版本上,我们支持了任意数量的参数,原有的写法都恢复支持,用户不需要去记格式了。

比如下面的格式也能输出的很好。

logger.info('123', [1, 2, 3], new Error('abc');

2、替换阿里云 FC 环境下的默认日志对象

在 FC 下,平台自带的日志输出,会出现无法输出的问题

比如(使用的是阿里云 context 上自带的 context.logger):

this.ctx.logger.error(new Error('ccc'));

这句简单的错误对象输出,原来的效果

Midway v2.11.2 发布,提供 Serverless 日志库支持

新版本我们将 context.logger 切换为了 midway 自带的 @midwayjs/logger 库(仅在阿里云 FC 环境),将会更好的输出信息。

新的错误输出:

Midway v2.11.2 发布,提供 Serverless 日志库支持

3、 bootstrap 时支持捕获额外的错误

之前在 bootstrap 中遗漏了对异步链错误的支持,在一些情况下会导致进程退出,虽然 pm2 等 工具 会记录最后的 error,但是为了优雅的处理和日志的统一性,还是需要增加这一监听。

新版本增加了 uncaughtExceptionunhandledRejection 的监听,让一些特殊的错误也能捕获输出。

比如下面的代码,如果监听了之后,就会输出 'got err',否则就会报一个全局的错误。

let a;

// process.on('uncaughtException', err => {
//	console.log('got err');
//});

async fuction run() {
  setTimeout(()  => {
    a();
  }, 100);
}

run();

// TypeError: a is not a function

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换