java - websphere liberty - 应用程序特定的日志记录配置

标签 java websphere-liberty

我在部署在 websphere liberty profile 上的应用程序中使用 SLF4J。我想对其进行配置,以便 1- 日志记录配置(例如,如果我将 log4j 与 slf4j 一起使用,则为 log4j 属性)驻留在应用程序 war 文件之外,2- 日志记录配置仅适用于我的应用程序,而不适用于部署在同一配置文件上的其他应用程序.

(1) 可以通过使用 slf4j 和 java.util.logging 来实现,因为 websphere liberty 已与其集成,但是日志记录配置适用于整个配置文件

但是,同时获得 (1) 和 (2) 的最佳方法是什么?

最佳答案

我最终使用了 org.apache.log4j.PropertyConfigurator 以及 java.nio.file.WatchService

watchservice 将监视预定义位置处的 log4j.properties 文件以了解更改。如果文件发生更改,它将调用此方法

/**
 * Update configuration.
 */
public void updateConfiguration() {
    Path path = configPath.resolve(LOG_FILE_NAME);
    if (Files.exists(path)){
        System.out.println(MessageFormat.format("Reloading logging configuration from {0}", path.toAbsolutePath()));
        PropertyConfigurator.configure(path.toAbsolutePath().toString());
    } else {
        System.err.println(MessageFormat.format("log4j.properties file was expected at {0} but was not present. Please create this file and configure it for logging to work.", path.toAbsolutePath()));
    }
}

这将允许在应用程序外部使用日志配置文件,该文件也可以在运行时更新。

关于java - websphere liberty - 应用程序特定的日志记录配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33034614/

相关文章:

java - GUI计算器计算

java - False Unused "private"方法应该被移除

java - 所有异步任务都可以读取的变量

Java HashMap 检测冲突

java - WebSphere Liberty Profile - 如何在部署 Spring Boot uber JAR 时添加安全约束

ibm-mobilefirst - IBM Worklight 5.0.5 - 领域未在authenticationConfig.xml 中定义

Java Swing 将对象添加到表中

java.lang.IllegalStateException : SRVE0199E: OutputStream already obtained

java - 使用与 Spring Batch 相同的输入参数启 Action 业时,Liberty Batch 不会引发异常(JobInstanceAlreadyExistsException)

java - Websphere Liberty - 如何从 Windows 注册表获取 keystore 密码?