- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想更改 Datastax 驱动程序记录器的日志级别,但经过多次尝试我无法弄清楚...
这是我使用的类:
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;
import com.datastax.driver.mapping.MappingManager;
public class CassandraSession {
/**
* CassandraSession singleton
*/
private static CassandraSession INSTANCE = null;
/**
* The Cassandra Cluster
*/
private static Cluster cluster;
/**
* The Cassandra Session
*/
private static Session session;
/**
* MappingManager is used to create Cassandra mappers
*/
private static MappingManager manager;
/**
* LOGGER
*/
private static final Logger LOGGER = Logger.getLogger(CassandraSession.class);
/**
* Keyspace Name
*/
private static final String KEYSPACE = "MY_KEYSPACE";
/**
* CassandraSession
*/
private CassandraSession() {
initialize();
}
/**
* This method initializes the connection with the Cassandra Database
*/
private void initialize() {
cluster = Cluster.builder().withClusterName("TestCluster").addContactPoints("127.0.0.1").withPort(9042).build();
final Metadata metadata = cluster.getMetadata();
LOGGER.info("Connected to cluster: " + metadata.getClusterName());
}
/**
* Get the instance of the singleton CassandraSession
*
* @return
*/
public static synchronized CassandraSession getInstance() {
if (INSTANCE == null) {
INSTANCE = new CassandraSession();
}
return INSTANCE;
}
/**
* Get the Cassandra Session
*
* @return
*/
public Session getSession() {
if (session == null) {
session = cluster.connect(KEYSPACE);
}
return session;
}
/**
* Get the Cassandra MappingManager
*
* @return
*/
public MappingManager getManager() {
if (manager == null) {
manager = new MappingManager(session);
}
return manager;
}
}
我尝试将 log4j.properties 文件放在 src/main/resources 中,以编程方式更改日志级别,但没有任何变化。我仍然得到以下痕迹:
11:39:48.762 [http-bio-8080-exec-6] DEBUG c.d.driver.core.SystemProperties - com.datastax.driver.NEW_NODE_DELAY_SECONDS is undefined, using default value 1
11:39:48.768 [http-bio-8080-exec-6] DEBUG c.d.driver.core.SystemProperties - com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE is undefined, using default value 8
11:39:48.770 [http-bio-8080-exec-6] DEBUG c.d.driver.core.SystemProperties - com.datastax.driver.NOTIF_LOCK_TIMEOUT_SECONDS is undefined, using default value 60
11:39:48.812 [http-bio-8080-exec-6] DEBUG com.datastax.driver.core.Cluster - Starting new cluster with contact points [/127.0.0.1:9042]
11:39:48.827 [http-bio-8080-exec-6] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
11:39:48.924 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
11:39:48.924 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
11:39:48.924 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
11:39:48.925 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: true
11:39:48.926 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent - Platform: Windows
11:39:48.926 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent - Java version: 8
11:39:48.926 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false
11:39:48.926 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available
11:39:48.927 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false
11:39:48.929 [http-bio-8080-exec-6] DEBUG i.n.util.internal.PlatformDependent - Javassist: unavailable
我从这些痕迹中可以看出,sl4j 被用作默认日志记录框架。那么我如何告诉 Datastax 的驱动程序使用我的记录器(其属性由我的服务器定义)。
使用的服务器:Apache TomEE Plume 1.7.2
Datastax 驱动程序版本:2.1.9
Cassandra 版本:2.2.1
谢谢。
最佳答案
感谢 Olivier 的回答,但此依赖项已在我的 pom.xml 中声明(我在提问前看到了您链接的页面)。
不过没关系,我找到了解决方案。实际上问题是关于 slf4j 绑定(bind)之间的冲突,我在 TomEE 的日志中看到了它。
我的 pom.xml 中有这个绑定(bind):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
还有这个库中的另一个绑定(bind):
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>2.2.1</version>
</dependency>
关于“logback-classic.jar”
那么解决方案就是排除它:
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>2.2.1</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>
谢谢。
关于java - Datastax 驱动程序日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34041190/
我正在阅读 Scylla 的文档,因为我们正计划从 DSE 迁移到本地 Scylla。然而,in their documentation ,他们说不支持 DSE SSTable 格式。 Here他们提
我正在使用与 Datastax Enterprise 捆绑在一起的 gremlin-console (v3.2.7)。启动时它会自动连接到远程 gremlin 服务器。接下来,我创建一个别名来访问右侧
我正在阅读 Scylla 的文档,因为我们正计划从 DSE 迁移到本地 Scylla。然而,in their documentation ,他们说不支持 DSE SSTable 格式。 Here他们提
有谁知道如何在使用 amazon ec2 M3.Xlarge 机器的集群中使用 Datastax 企业(使用 opscenter)? 当我尝试使用这些类型的实例(使用 ssd)时,出现以下错误: 启动
我了解 DSE 5.1 运行 Solr 6.0 版本。我正在尝试使用 Solr 本地参数来使用 facet.pivot 功能,但它似乎不起作用。 我的数据如下 Simple 4 fields 我需要的
我在 Datastax 4.6 集群上有一个大型但简单的 Cassandra 数据库。对于这个非常简单的用例来说,许可证续订是禁止的,我正在尝试迁移到直接的 Apache 或 Datastax Com
我正在尝试在 Windows 7 机器上使用 Datastax C# 客户端驱动程序连接到在虚拟机器 (Ubuntu) 上运行的 DSE Cassandra。 这是我的代码: Cluster _clu
我从 CLI 中创建了这样的列族- create column family profile with key_validation_class = 'UTF8Type' and co
我正在使用 OpsCenter 5.1.1 运行 DSE 4.6.5 集群 (Cassandra 2.0.14.352) 一天一两次,其中一个节点(有时更多)停止报告指标,直到我手动重新启动 data
我需要在 cassandra 的表中选择不同的计数。 据我所知,cassandra 不支持直接不同计数,甚至像 rdbms 这样的嵌套查询也不支持。 select count(*) from (sel
我在尝试为创建的角色授予权限时遇到异常。 命令: GRANT ALL PERMISSIONS on KEYSPACE test_ks to ks_admin; 错误: ServerError: jav
我刚刚安装了 DataStax DevCenter。但是在加载时,会弹出自动更新和使用页面。但是,“确定”按钮被禁用且无法点击。所以我无法通过应用程序的启动加载。我怎样才能绕过这个? Click he
我试图在本地启动DSE 5.0.1 Cassandra(单节点)。 出现以下错误: CassandraDaemon.java:698 - Cannot start node if snitch's d
我刚刚安装了DataStax Community Edition,但是在尝试运行以下命令时; C:\> net start DataStax_DDC_Server 我得到以下回应: 谢谢 最佳答案 我
我使用 datastax java 驱动程序构建了一个选择查询。我使用限制选项设置限制。但是我看到另一个也可以设置的属性 setFetchSize(整数大小) 根据文档,DEFAULT_FETCH_S
刚刚在我的 Mac 上安装(从下载的 dmg 复制应用程序)DevCenter 1.6,运行安装了 jdk 8u152 的 macOs Sierra 10.12.6。应用程序加载了一个 UI(启动画面
我们可以像这样创建一个集群实例。 cluster = Cluster .builder() .addContactPoint("192.168.0.30") .withRetryPolicy(Def
我在127.0.1.1上运行自己的cassandra版本。我将rpc_address和address更改为127.0.1.1。 当我启动 Opscenter 时,系统会提示我安装agents,并通过推
我正在使用 Cassandra 1.2.5 和二级索引。当我运行准备好的语句时,没有返回数据。我有数据。另外,对于索引列,我确实有重复的值。我正在做的是根据 user_id 重新调整 video_id
我正在使用 Datastax 可爱的 cassandra java 驱动程序。我试图将所有查询字符串封装到内置访问器中以进行映射,但我需要能够设置查询的分页状态。 我发现这可以通过普通语句(Simpl
我是一名优秀的程序员,十分优秀!