猫鼬调试写入STDERR吗? [英] Mongoose debug writes to STDERR?

查看:63
本文介绍了猫鼬调试写入STDERR吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题,啊!

有人知道为什么要用猫鼬将调试日志写入stderr吗?反正有写到stdout的东西吗?

Does anyone know / have info about why mongoose writes its debug log to stderr? Is there anyway to write it to stdout?

推荐答案

debug选项接受一个函数而不是布尔值:

The debug option accepts a function instead of a boolean:

mongoose.set("debug", function (collection, method, paramA, paramB, paramC) {

    console.log(collection)
    console.log(method)
    console.log(paramA)
    console.log(paramB)
    console.log(paramC)
})

我放paramA, paramB, paramC的原因是因为参数取决于所使用的方法和选项:

The reason I put paramA, paramB, paramC is because the arguments are dependent upon the method and options being used:

Person.create({firstName: "john"}, callback)
// people
// insert
// {firstName: "john"}
// undefined
// undefined

Person.update({firstName: "john"}, {lastName: "doe"}, {new: true}, callback);
// people
// update
// {firstName: "john"}
// {$set: {lastName: "doe"}}
// {new: true}

Person.find({firstName: "john"}, callback);
// people
// find
// {firstName: "john"}
// undefined
// undefined

Person.find({firstName: "john"}, {limit: 1}, callback);
// people
// find
// {firstName: "john"}
// {limit: 1}
// undefined

正在记录的信息是 Mongodb 输入,而不是 Mongoose 输入.您可以在update()方法中看到,paramB{$set: {lastName: "doe"}}的形式出现.在幕后,猫鼬将更新转换为使用$set,这就是为什么记录了该原因.

The info being logged is the Mongodb input, not the Mongoose input. You can see this in the update() method, paramB comes out as {$set: {lastName: "doe"}}. Behind the scenes, Mongoose converts updates to use $set, which is why that is logged.

由此,您可以轻松地按自己的意愿格式化它,然后process.stdout.write()

From this, you can easily just format it however you want and process.stdout.write()

这篇关于猫鼬调试写入STDERR吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆