cappedMax在Ubuntu上的Node.js中的winston-mongodb记录器中不起作用 [英] cappedMax not working in winston-mongodb logger in Node.js on Ubuntu
问题描述
我已经使用winston模块在Node.js中创建了一个记录器,并通过要求具有以下选项的winston-mongodb模块来添加MongoDB传输:
I have created a logger in Node.js using the winston module and added MongoDB transport by requiring winston-mongodb module with the following options:
{
db: config.db[k.DB_ENV.AUTHOR],
username: config.dbUser,
password: config.dbPassword,
collection: 'log-aggregation',
storeHost: true,
capped: true,
cappedMax: 10 // documents
}
我希望记录器为每10个文档创建一个新集合.但是记录器会继续登录相同集合.我评论了collection: 'log-aggregation'
行,以检查选项是否真的起作用,然后开始记录到默认的'log'
集合.
I expect the logger to create a new collection for every 10 documents. But the logger continue logging in the same collection. I commented the collection: 'log-aggregation'
line to check if the options are really working and then it began to log to the default 'log'
collection.
那我的错误在哪里? cappedMax
选项是否没有最小文档大小?我尝试使用cappedSize
选项(也具有10到1000个值)来进行此操作,但仍未创建新集合.
So where is my mistake? Is there a minimum no of document size to the cappedMax
option? I tried this with cappedSize
option also with 10 to 1000 values, still the new collections are not created.
我想知道cappedSize和cappedMax选项的最小和最大允许值吗?
I want to know the minimum and maximum permissible value for cappedSize and cappedMax option?
我还想知道创建的新馆藏的名称是什么?
I also want to know what will be the name of new collections created?
推荐答案
这是我用来获取多个日志的方法:
This is what I use to get multiple logs:
var winston = require('winston');
require('winston-mongodb').MongoDB;
winston.loggers.add('userLog',{
transports : [
new(winston.transports.MongoDB)({
db : 'mongodb://username:password.mongolab.com:5555/log_db',
collection : 'userLog',
capped : true
}),
]
});
winston.loggers.add('profileLog',{
transports : [
new(winston.transports.MongoDB)({
db : 'mongodb://username:password.mongolab.com:5555/log_db', collection : 'profileLog',
capped : true
}),
]
});
它运行良好,没有明显的延迟.
And it works fine with no observable latency.
P.S.您可以在capped:true
玩得开心!
这篇关于cappedMax在Ubuntu上的Node.js中的winston-mongodb记录器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!