【发布时间】:2023-03-31 11:50:01
【问题描述】:
读完之后,我觉得我明白了,现在我感到困惑。以下是我的期望和我所做的:
我希望登录到 Karaf,重新加载我的包,然后运行 log:tail 并最终看到如下日志消息:
13:28:47.265 INFO [Blueprint] You just created a class called: MyClass.
使用的技术: - 由 Apache Karaf 实现的 OSGI 容器 - 白羊座实现的蓝图
-
我的 OSGI 包从 Karaf 导入 pax 记录器
org.slf4j.*; provider=paxlogging
据我了解,这意味着对 Karaf 的单例记录器的引用将在运行时提供给我的应用程序,该应用程序仅使用 API。
我的类使用SLF4J接口,所以我的项目中存在依赖
slf4j-api:slf4j-api:1.7.26。存在一个类
类服务于模型
public class MyClass {
private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
public MyClass() {
LOGGER.info("You just created a class called: {}", this);
}
@Override
public String toString() { return "MyClass" };
}
我只是遵循 OSGI LoggerFactory 的规范:
此 API 的使用者不得实现此类型https://osgi.org/specification/osgi.cmpn/7.0.0/service.log.html#org.osgi.service.log.LoggerFactory
- 白羊座创造了一个:
蓝图 XML
<?xml version="1.0" encoding="UTF-8" ?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<description>
A sample Blueprint XML to demonstrate
the initialization procedure in the hopes of reproducing a problem.
</description>
<bean id="myclass1" class=com.stack.MyClass/>
</blueprint>
相关
【问题讨论】:
标签: logging osgi apache-karaf blueprint-osgi blueprint