- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在渲染来自kafka总线的事件并使用winston logger写入文件系统,现在为了增强一些功能,用户希望从文件中搜索事件,因此出于这个特殊原因,我想为我们正在编写的每个事件生成一些id记录文件。所以我的问题是,当我们登录到文件时,是否可以使用 winston
生成某种 id。
winstonServer.js
var Consumer = {
start: function() {
var logger = new(winston.Logger)({
level: null,
transports: [
new(winston.transports.Console)(),
new(winston.transports.File)({
filename: './logs/dit/server.log',
maxsize: 1024 * 1024 * 15, // 15MB
timestamp: false,
maxFiles: 10,
json: false,
formatter: function(options) {
return options.message;
}
})
]
});
function startConsumer(consumer) {
consumer.on('message', function(message) {
logger.log('info', message.value);
io.io().emit('ditConsumer', message.value);
});
consumer.on('error', function(err) {
console.log('error', err);
});
};
startConsumer(consumer);
}
}
服务器日志
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took 43fd41a7-d1fb-4c19-9de6-19170aee171f a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
最佳答案
首先你可以生成UUID(npm install node-uuid --save
):
const uuid = require('node-uuid');
,然后我们有2个解决方案:
通过字符串插值将其添加到日志消息:
...
function startConsumer(consumer) {
consumer.on('message', function(message) {
logger.log('info', `[ID:${uuid.v4()}]${message.value}`);
io.io().emit('ditConsumer', message.val);
});
consumer.on('error', function(err) {
console.log('error', err);
});
};
startConsumer(consumer);
...
通过元将其添加到日志消息 - 这允许两种传输之间的一致性:
var Consumer = {
start: function() {
const formatter = function(options) {
return `[ID:${options.meta.ID}]${options.value || options.meta.value}`;
};
var logger = new(winston.Logger)({
level: null,
transports: [
new(winston.transports.Console)({formatter}),
new(winston.transports.File)({
filename: './logs/dit/server.log',
maxsize: 1024 * 1024 * 15, // 15MB
timestamp: false,
maxFiles: 10,
json: false,
formatter
})
]
});
function startConsumer(consumer) {
consumer.on('message', function(message) {
logger.log('info', message.value, {ID:uuid.v4(), value:message:value});
io.io().emit('ditConsumer', message.value );
});
consumer.on('error', function(err) {
console.log('error', err);
});
};
startConsumer(consumer);
} }
关于javascript - 如何使用winston 日志记录创建事件ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42559229/
我正在使用 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
我是一名优秀的程序员,十分优秀!