- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 winston 进行如下日志记录。
const winston = require('winston');
const {transports, format, createLogger } = winston;
const { combine,errors, splat,timestamp } = format;
const logger = createLogger({
level: process.env.LOG_LEVEL,
transports: [
new transports.Console({
format: combine(
timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
errors({stack: true}),
splat(),
winston.format.colorize(),
format.json()
)
})
]
});
module.exports = {logger};
并且在控制台中它显示符号而不是颜色,如下所示
{
"message": "apiKeyId: ef12dv3n3b",
"level": "\u001b[34mdebug\u001b[39m",
"timestamp": "2019-08-20 07:07:16"
}
我该如何解决?
最佳答案
我刚刚也在尝试从 NodeJS 输出到 Cloudwatch。并发现了同样的问题,根据我使用的组合,级别和/或消息出现奇怪的字符编码。我想这也是因为颜色。并找到了这个问题。
我猜你不能改变颜色。
我发现了一些 Chrome 扩展程序(未尝试),例如“Colorize CloudWatch”,这可能是一种绕过它的方法。我假设他们根据级别在浏览器中设置颜色。
我目前正在试用 WinstonCloudwatch 传输而不是控制台 (https://github.com/lazywithclass/winston-cloudwatch),到目前为止还没有看到字符编码问题。尽管据我所见,Cloudwatch 仍然 控制颜色,因此您会得到标准的灰色/绿色 JSON。
这是我目前正在试验的格式化程序(没有颜色),设置为 messageFormatter: cloudwatchFormat
:
const cloudwatchFormat = function (info, opts) {
const message = info.message;
const splat = info[Symbol.for('splat')];
const splatFormatted = splat ? splat.map((s) => (typeof s === 'string' ? s : JSON.stringify(s))) : '';
return JSON.stringify({
timestamp: new Date().toISOString(),
level: info.level,
message: message,
variables: splatFormatted
});
}
关于amazon-cloudwatch - 而不是颜色,符号出现在 aws cloudwatch 控制台与 winston,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57568393/
我正在使用 winston、expressWinston、winston-mongoDB 来管理我的 NodeJs 应用程序中的日志。 同时使用 winston-mongodb transport 和
当我的应用程序启动时,winston 会记录各种信息,例如 winston:create-logger Define prototype method for "error" winston:crea
我正在使用 winston logger 和 wnat 进行流式输入。但我不知道我应该传递给什么。我的记录器: const logger = createLogger({ ... }); Missin
winston.createLogger();显然不是构造函数。为什么会这样? 我看到有些人尝试回滚到winston@3.0.0,但这对我不起作用。我使用的是最新版本的 winston 。以下是 lo
几年前我和 winston 一起工作。当我们在 localhost 上进行开发时,我们的 winston 被配置为输出格式良好、易于阅读的 JSON。 2.x winston npm install
我正在尝试使用 express-winston 和 winston-mongodb 将请求/响应记录到 NodeJS 项目中的 MongoDB。这是我到目前为止工作的示例代码; const expre
我正在尝试在 Node js 中实现一个记录器,它将每天以自定义格式的日志创建一个新的日志文件 为此我使用了三个包 winston morgan winston-daily-rotate-file 所
将 winston 更新至 3.0.0运行我的nodejs应用程序时出现此错误出现以下错误 TypeError: colors[Colorizer.allColors[lookup]] is no
编辑:找到答案,并为 future 的读者发布完整的答案。 我已经掌握了winston logging的基础知识在 Node.js 中,并希望更多地自定义我的日志记录。这是我到目前为止所拥有的: va
我正在使用 winston 登录 Sails 应用程序。这是我的配置: var customLogger = new winston.Logger({ transports: [
所以我使用winston-daily-rotate-file。在 app.js 中我有: var logger = require('./logger'); 然后: logger.info("logg
现在我使用 Winston 来记录最大大小和每日轮换 我希望每个 API 端点都有一个文件,从而定义多个日志文件 我怎样才能实现这一目标? 这是我的 winston 助手类 import * as w
我想在 node 应用程序中使用 winston 记录器将错误记录到文件中。但是 winston 没有写入文件。 var logger = new (winston.Logger)({
我正在使用 创建完整的平均堆栈应用程序 NodeJs , Angular 6 , ExpressJs and MongoDB 我已经成功创建了一个服务器,并且它工作得很好,在我的应用程序中记录错误时,
我正在使用 Winston ^3.0.0-rc6,如下所示: var options = { file: { level: 'info', filename:
我尝试向 winston 添加自定义日志级别。这是记录器的代码: const write = new (winston.Logger)({ transports: [
这是我的 winston 记录器 - var winston = require('winston') var logger = new (winston.Logger)({ transports
我正在使用这样的东西: var winston = require('winston'), logger = new (winston.Logger)({ transports: [ ne
Flatiron 的日志记录库 Winston 非常有用,但我不知道如何为记录器分配名称。我期待与其他日志库类似的输出,例如: [] [] - 是否可以这样配置Winston? 谢谢。 最佳答案
我写了一个小模块,使用 winston 来记录东西。 我使用了 sudo npm install -g winston(它在 vm 上...所以我不太关心 sudo 等。 来自 npm 的日志: wi
我是一名优秀的程序员,十分优秀!