如何将 MongoDb 的日志记录级别设置为 info?

发布于 2024-12-26 07:34:49 字数 411 浏览 1 评论 0原文

我有一个在背面使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光瘦了 2025-01-02 07:34:49

我在测试中遇到了问题,所以我最终在我的spec_helper.rb中执行了以下操作:

Mongoid.logger.level = Logger::INFO

但是,如果您在rails内部,您可能应该(未经测试)使用它来访问记录器:

config.mongoid.logger

I had problems with this in my tests, so I ended up doing the following in my spec_helper.rb:

Mongoid.logger.level = Logger::INFO

However if you are inside of rails you should probably (untested) use this to access the logger instead:

config.mongoid.logger
稍尽春風 2025-01-02 07:34:49

日志记录级别是指 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.

陈年往事 2025-01-02 07:34:49

如果您使用的是 mongoid 2.2 或更高版本,则可以在 mongoid.yml 中进行设置:

production:
  hosts:
    ...
  database: ...
  logger: false

此外,这确实会对性能产生影响。当我在生产环境中关闭 mongo 日志记录时,我发现在使用 apachebench 进行的 30 分钟负载测试中,垃圾收集减少了,应用程序实例内存占用减少了约 15 MB。

If you're using mongoid 2.2 or higher, you can set it in mongoid.yml:

production:
  hosts:
    ...
  database: ...
  logger: false

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文