无法让 Karaf 4.2.6 使用 log4j2 和 JsonLayout 作为布局类型进行日志记录

2024-04-22

我一整天都在做这件事,但在尝试了这么多组合后却没有让它发挥作用。归根结底,我正在寻找从 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.

我看了看罐子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生成了。有时,我想要的应用程序功能甚至无法启动,因为如果我只是将对这些 jar 的引用放置在设置日志记录时,有关配置的某些内容会被阻止startup.properties, 例如

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包含具有正确启动级别的杰克逊罐子。

我正在 Kubernetes 中运行容器,并希望 Kubernetes 中的标准日志收集能够正常工作。我在日志收集器上使用额外的插件,至少将内容分离为 JSON 格式,但它很容易出错,我宁愿从 JSON 格式的日志开始,而不是稍后在下游处理,这样我就可以分离日志的组件记录,例如记录时执行操作的人。

我在 Stack Overflow 上进行了搜索,在 Google 上进行了搜索,并找到了提示,但没有明确的步骤来提供解决方案。我意识到这里没有明确的文件列表,但是,正如我所说,我经历了很多组合。任何帮助将非常感激。我还将在 Karaf 用户组上发帖。


好吧,几天后,我想出了需要做的一切。感谢@GrzegorzGrzybek 的帮助。

我需要以下几行

mvn\:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4 = 8
mvn\:com.fasterxml.jackson.core/jackson-core/2.9.10 = 8
mvn\:com.fasterxml.jackson.core/jackson-annotations/2.9.10 = 8
mvn\:com.fasterxml.jackson.core/jackson-databind/2.9.10 = 8

添加到我的etc/startup.properties。如果我只是编辑文件来添加它们,并确保我的文件位于system存储库,它不会工作。不知道,某些条目没有在其他地方创建etc配置,因此容器无法启动,或者某些功能集在wrap安装了处理程序,因此整个容器将停止运转。

我尝试了很多组合,但最终找到了如何将东西放进去etc/startup.properties。我将我想要的捆绑包放入他们自己的功能中,并设置了我希望它们具有的起始级别。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" name="myapp-common-container-feature">
  <feature name="com.me.myapp.logging.provider" version="0.12.0" description="MyApp Logging Provider">
    <bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-annotations/2.9.10</bundle>
    <bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-core/2.9.10</bundle>
    <bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-databind/2.9.10</bundle>
    <bundle start-level="8">mvn:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4</bundle>
  </feature>
</features>

注意start-level属性。

然后,在我的程序集 POM 中,我添加了以下依赖项:

        <dependency>
            <groupId>com.me.myapp</groupId>
            <artifactId>myapp-common-container-feature</artifactId>
            <version>0.12.0</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>compile</scope>
        </dependency>

这里重要的一行是<scope>compile</scope>。特点在compile范围将被放置在startup.properties如果放置在<startupFeatures />在 Karaf Maven 插件的配置中。

            <plugin>
                <groupId>org.apache.karaf.tooling</groupId>
                <artifactId>karaf-maven-plugin</artifactId>
                <configuration>
                  <startupFeatures>                
                    <feature>com.me.myapp.logging.provider/0.12.0</feature>
                  </startupFeatures>

现在容器启动时带有 JSON 日志记录。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法让 Karaf 4.2.6 使用 log4j2 和 JsonLayout 作为布局类型进行日志记录 的相关文章

随机推荐

  • SQL 查询中的“NOT LIKE”

    为什么这个简单的查询会返回 ORA 00936 缺少表达式 正如您所知 数据库是 Oracle SELECT FROM transactions WHERE id NOT LIKE 1 AND NOT LIKE 2 我觉得自己很傻 但我做错
  • 如何使用 MS SQL 2008 获取数据库中的表列表?

    我想验证数据库中是否存在表 如果不存在 则创建它 如何获取当前数据库中所有表的列表 我可以使用这样的 SELECT 获取数据库列表 SELECT FROM sys databases 剩下的就是创建该表 如果该表不存在 我还尝试与数据库同时
  • +exposeBinding 不起作用

    我试图在 NSWindowController 的子类中公开自定义绑定 我在子类中添加了以下代码 void initialize self exposeBinding customBinding 然后 在 IB 中 我有一个子类的对象实例
  • 如何暂停使用DownloadManager?

    我想实现下载时 可以由用户暂停 停止 如何使用 DownloadManager 实现此目的 You can 删除下载 http developer android com reference android app DownloadMana
  • 如何从外部网站重新创建图像预览?

    与 Facebook 的 UI 类似 我尝试从外部链接网站生成预览图像 这样 当用户输入要链接的 url 时 UI 将默认扫描该网站以查找图像并抓取预览缩略图 这项技术有具体的名称吗 或者有人可以指出我学习这个的方向吗 非常感谢 其名为刮
  • 如何调整外部 SWF 的大小以适合容器?

    我想要完成的是调整外部 SWF 的大小 使其适合在舞台上作为容器呈现的显示对象 现在它显示在容器外部 重要提示 我不希望外部 SWF 占据整个舞台 我在舞台上为它准备了一个特殊的地方 那个容器 public function loaderC
  • Perl CGI 脚本根据运行返回不同的结果

    我有一个 Perl CGI 脚本 它明显随机地发出不同的 HTML 所有输入都没有改变 例如 我会跑wget两次并得到两个不同的结果 CGI 由开发数据库支持 该数据库也不会改变 我有一个调试语句 通知我相同数量的元素从数据库返回到脚本中
  • 将 csv 数据写入命名空间内的矩阵时,TCL 抛出无效命令名称

    这是一个奇怪的问题 我似乎无法弄清楚 我正在使用 TCL 8 5 我正在尝试使用以下命令将数据从 CSV 文件读取到矩阵中csv read2matrix命令 然而 每次我这样做时 它都会说我试图写入的矩阵是无效命令 我正在做的事情的片段 p
  • 嵌入式 JavaScript 中的特殊字符

    我有一些嵌入在 html 文件中的 javascript 如下所示 它有一条像这样的线 if os Mac br Safari br Chrome 一切顺利 这意味着脚本可以工作 但是验证者 http validator w3 org 正在
  • 在 App Engine 标准 python 中使用 Google Stackdriver 日志时出错

    我的堆栈 谷歌应用程序引擎标准Python 2 7 Goal 要在 Google Stackdriver Logging 中创建命名日志 https console cloud google com logs viewer https co
  • 如何将这些数据存储在cookies中?

    假设我有一些文本框 文本区域 其中的值必须存储 这些值必须在按键时存储 以便当用户过早关闭页面时不会丢失数据 这是我当前的代码 使用cookie function createCookie name value days if days v
  • 箭头呢?

    阅读有关 Haskell 各种类别主题课程的各种教程 我们发现诸如Monoid Functor Monad等等 所有这些都有数十个实例 但由于某种原因 当我们到达Arrow 只有两个实例 函数和 monad 在这两种情况下 使用Arrow与
  • 如何使用 Go 的 flag 包打印位置参数的用法?

    鉴于这个简单的 Go 程序只需要一个命令行参数 我该如何改进它以便flag Usage 给出有用的输出 package main import flag fmt os func main flag Parse if len flag Arg
  • Python中不可变对象的类型是什么(对于mypy)

    我总是用mypy in my Python程式 类型是什么 来自typing 对于不可变对象 那些可以用作字典键的对象 回到上下文中 我想编写一个从字典继承的类 并且我有以下代码 class SliceableDict dict def g
  • Pthreads 与 OpenMP

    我正在使用 Linux 用 C 创建一个多线程应用程序 我不确定是否应该使用 POSIX 线程 API 还是 OpenMP API 使用两者有何优缺点 Edit 有人可以澄清这两个 API 是否创建内核级 or 用户级线程 Pthreads
  • 获取特定时区的当前时间

    我有一个具有不同时区的日期和时间格式的数据框 我想将其与该时区的当前时间进行比较 所以我想在下面的 日期和时间 列中添加 1 小时 然后将其与该时区的当前时间进行比较 就像第一个一样 时区是 EDT 当前时间是 2017 07 18 10
  • Java 枚举和 Switch 语句 - 默认情况?

    对于建议抛出异常的人 抛出异常不会给我带来编译时错误 它会给我带来运行时错误 我知道我可以抛出异常 我宁愿在编译期间死也不愿在运行时死 首先 我使用的是 eclipse 3 4 我有一个数据模型 其模式属性是枚举 enum Mode on
  • Windows 上的异步子进程

    首先 我要解决的总体问题比我在这里展示的要复杂一些 所以请不要告诉我 使用阻塞线程 因为如果没有公平 公平的重写 它就无法解决我的实际情况重构 我有几个不需要我修改的应用程序 它们从标准输入获取数据 并在发挥其魔力后将其输出到标准输出 我的
  • WordPress 树枝模板短代码不显示

    我在 Wordpress 中使用 Symfony Twig 模板 一切运行良好 除了我无法在页面模板中显示任何短代码 我正在尝试使用 Contact form 7 插件显示联系表单 短代码是这样的 contact form 7 id 123
  • 无法让 Karaf 4.2.6 使用 log4j2 和 JsonLayout 作为布局类型进行日志记录

    我一整天都在做这件事 但在尝试了这么多组合后却没有让它发挥作用 归根结底 我正在寻找从 Karaf 获取 JSON 日志记录的明确步骤列表 我什至浏览了 Maven Karaf 插件源代码 试图解决这个问题 尽管也许我看的还不够远 我正在使