如何使用 MongoDB Java 驱动程序和 WildFly 配置日志记录

huangapple 未分类评论49阅读模式
英文:

How to configure logging with mongodb java driver and wildfly

问题

我的设置是一个使用Java 8构建的Web应用程序(war包),并在Wildfly 17.0.1上运行。

问题:在开发过程中(但在生产环境中也是如此,使用文件记录器),我需要打印出应用程序的查询。对于关系数据库(例如Postgres),在使用JPA时很简单:进入persistenc.xml文件并将以下行设置为true:

  1. <property name="hibernate.show_sql" value="true" />
  2. <property name="hibernate.format_sql" value="true" />

然而在MongoDB中,我找不到类似的配置或选项,因此我无法记录每个查询以了解MongoDB Java驱动正在执行的操作。

为了澄清:

  • 日志记录器:org.jboss.logging.Logger
  • slf4j已在类路径中(作为Gradle传递依赖项的org.slf4j:slf4j-api:1.7.28)
  • 我尝试在Wildfly控制台应用程序中配置一个用于org.mongodb.driver包的日志记录器,但在任何级别上都不起作用。
英文:

My setup is a web application ( war ) built with java 8 and running using wildfly 17.0.1

Problem: during development ( but also in production on a file logger ) I need to print out application's queries. This for relational database (for example Postgres ) using jpa is simple: go to persistenc.xml and set to true following lines:

  1. <property name="hibernate.show_sql" value="true" />
  2. <property name="hibernate.format_sql" value="true" />

with mongodb I'm not able to found a similar configuration or options, so I'm not able to log every query to mondob java driver is doing.

For clarification:

  • logger : org.jboss.logging.Logger
  • slf4j is in the classpath ( org.slf4j:slf4j-api:1.7.28 as gradle transitive dependency )
  • I've tried to configure inside wildfly console application a logger on package org.mongodb.driver , but is not working on any level

huangapple
  • 本文由 发表于 2020年4月9日 16:11:36
  • 转载请务必保留本文链接:https://java.coder-hub.com/61116670.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定