【发布时间】:2020-04-29 03:18:12
【问题描述】:
在尝试了这么多组合之后,我整天都在做这个,但没有让它发挥作用。归根结底,我正在寻找从 Karaf 获取 JSON 日志记录的明确步骤列表。我什至浏览了 Maven Karaf 插件源代码,试图解决这个问题,但也许我看的还不够远。
我使用的是 Karaf 4.2.6。我正在尝试使用 karaf-maven-plugin 版本 4.2.6 构建 Karaf 部署。
如果我将各种附加程序的 layout.type 更改为 JsonLayout,我会收到一个堆栈跟踪,说它无法加载 JSON 布局,因为我缺少一个类。 java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider.
我查看了 jar org.ops4j.pax.logging/pax-logging-log4j2/1.10.2,发现我需要 3 个 Jackson jar,Core v2.8.7、Annotations v2.8.0 和 Databind v2.8.7。
我一直在尝试将这些文件放在etc/startup.properties 中,起始级别为 5 或起始级别为 8,以便它们在启动时为org.ops4j.pax.logging/pax-logging-log4j2/1.10.2 做好准备。我确保它们位于正确位置的system 文件夹中。大多数情况下,如果我确实让他们进入etc/startup.properties,他们的起始级别为 30。我将它们放置在具有正确起始级别的功能中,但它们要么在使用 startup.properties 之后很好地开始,要么就从来没有出现。我尝试了许多可能的组合,startupBundles、startupFeatures、bootFeatures,但在startup.properties 中没有得到它。我无法弄清楚startup.properties 的内容是如何生成的。有时,我想要的应用程序功能甚至无法启动,因为如果我只是在 startup.properties 中放置对这些 jar 的引用,则在设置日志记录时会阻止有关配置的某些内容,例如
mvn\:com.fasterxml.jackson.core/jackson-core/2.8.7 = 5
下面是我的 pom.xml,之前的尝试注释掉了:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<my_version>0.0.0</my_version>
<myapp_common_version>0.0.0</myapp_common_version>
</properties>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-karaf</artifactId>
<version>${my_version}</version>
<packaging>karaf-assembly</packaging>
<name>myapp-karaf</name>
<description>myapp-karaf details</description>
<repositories>
<!-- Apache ServiceMix repository (for region) -->
<repository>
<id>apache.servicemix.m2</id>
<name>Apache ServiceMix M2 repository</name>
<url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- OPS4J SNAPSHOT repository -->
<repository>
<id>ops4j.sonatype.snapshots.deploy</id>
<name>OPS4J snapshot repository</name>
<url>https://oss.sonatype.org/content/repositories/ops4j-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- Apache SNAPSHOT -->
<repository>
<id>apache.snapshots.deploy</id>
<name>Apache snapshot repository</name>
<url>https://repository.apache.org/content/groups/snapshots-group</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.2.6</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>spring</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-common-feature</artifactId>
<version>${myapp_common_version}</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-feature</artifactId>
<!-- Annoyingly this cannot come from an environment variable -->
<version>${my_version}</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${env.MYAPP_SOURCE_HOME}/myapp-common/server/karaf/assembly</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/filtered-resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.2.6</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>process-resources</id>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<startupBundles> <!--
<bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/2.8.0</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.8.7</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.8.7</bundle> -->
</startupBundles>
<installedFeatures>
</installedFeatures>
<startupFeatures>
<feature>com.me.myapp/${my_version}</feature>
</startupFeatures>
<bootFeatures>
<feature>com.me.myapp.logging.provider/${myapp_common_version}</feature>
<!-- standard distribution -->
<!-- <feature>standard</feature> -->
<!-- minimal distribution -->
<!--<feature>minimal</feature>-->
<feature>jaas</feature>
<feature>shell</feature>
<feature>ssh</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>instance</feature>
<feature>kar</feature>
<feature>wrap</feature>
<feature>log</feature>
<feature>package</feature>
<feature>service</feature>
<feature>system</feature>
</bootFeatures>
<javase>1.8</javase>
</configuration>
</plugin>
</plugins>
</build>
</project>
com.me.myapp.logging.provider 包含具有正确启动级别的 Jackson 罐子。
我在 Kubernetes 中运行我的容器,并希望 Kubernetes 中的标准日志收集能够正常工作。我在日志收集器上使用了一个额外的插件,至少将一些东西分成了 JSON 格式,但它很容易出错,我宁愿从 JSON 格式的日志开始,而不是稍后处理下游,这样我就可以分离记录,例如在记录时执行操作的人。
我在 Stack Overflow 上进行了搜索,谷歌搜索并找到了提示,但没有明确的步骤可以找到解决方案。我意识到这里没有明确的文件列表,但是,正如我所说,我经历了很多组合。任何帮助将非常感激。我也会在 Karaf 用户组发帖。
【问题讨论】:
-
ops4j1.jira.com/browse/PAXLOGGING-260 修复了 pax-logging-log4j2-extra,它是一个片段包,它“带来”了对原始 pax-logging-log4j2 的额外导入。你添加了这个额外的片段吗? Karaf 的github.com/apache/karaf/blob/master/assemblies/features/… 不包含这个额外的片段。
-
已添加,仍然失败。打算尝试一些事情,看看我是否至少可以手动完成一些工作。我注意到额外的导入在可选导入中没有版本,并且我的应用程序中有更新版本的 Jackson。也许我目前的问题来自于此,我将查看 pax-log4j2 等的 OSGi 清单。仍在尝试了解事情是如何进入 startup.properties 的。如果您有任何想法@GrzegorzGrzybek,请告诉我。
-
我唯一能建议的是检查 github.com/ops4j/org.ops4j.pax.logging/tree/pax-logging-1.11.x/… 中的 Pax Logging 1.11.x Karaf 测试 - 有针对当前和缺少的“额外”包的测试。
标签: json maven logging log4j2 apache-karaf