如何将 MongoDb 的日志记录级别设置为 info?
我有一个在背面使用 MongoDb 的 Rails 应用程序。我收到这些消息,上面写着 MONGODB [警告] 请注意,日志记录会对客户端性能产生负面影响。您应该在我的日志中将日志记录级别设置为不低于 :info in production
。好吧,我从来没有担心过,但现在决定查一下。
mongo 站点上的此页面 并未真正讨论日志记录级别,但它确实讨论了< code>-v 与 -vvvv
的详细程度。这和日志级别一样吗?就像 -vvvvv
与调试日志级别相同,而 -v
与错误日志级别相同?文档关于这个主题非常不清楚。
I have a Rails app that uses MongoDb on the back. I have these messages that say MONGODB [WARNING] Please note that logging negatively impacts client-side performance. You should set your logging level no lower than :info in production
in my logs. OK, I never worried about it but decided to look it up just now.
This page on the mongo site doesn't really discuss logging levels, but it does discuss -v
vs -vvvv
for verbosity. Is that the same thing as log level? As in -vvvvv
is the same as a debug log level and -v
is the same as an error log level? The docs are very unclear on this topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在测试中遇到了问题,所以我最终在我的spec_helper.rb中执行了以下操作:
但是,如果您在rails内部,您可能应该(未经测试)使用它来访问记录器:
I had problems with this in my tests, so I ended up doing the following in my spec_helper.rb:
However if you are inside of rails you should probably (untested) use this to access the logger instead:
日志记录级别是指 Rails 日志记录级别,而 -v 标志是指详细程度。
Rails 会自动将生产中的日志级别设置为高于开发中的日志级别,因此您无需担心。
Logging levels refer to rails logging levels whereas the -v flag refers to verbosity.
Rails automatically sets the logging level higher in production than when in development so you shouldn't have anything to worry about.
如果您使用的是 mongoid 2.2 或更高版本,则可以在 mongoid.yml 中进行设置:
此外,这确实会对性能产生影响。当我在生产环境中关闭 mongo 日志记录时,我发现在使用 apachebench 进行的 30 分钟负载测试中,垃圾收集减少了,应用程序实例内存占用减少了约 15 MB。
If you're using mongoid 2.2 or higher, you can set it in mongoid.yml:
Also, this does have a performance impact. When I turned off mongo logging in production, I saw fewer garbage collections and app instance memory footprints were about 15 megabytes smaller during 30-minute load tests using apachebench.