将 log4j.properties 转换为 log4j.xml 的脚本
我需要使用自定义过滤器,因此我需要将一些长 log4j.properties 文件转换为 log4j.xml。
有人知道有一种工具可以做到这一点,或者愿意贡献一个他们使用过的工具吗?到目前为止,搜索还没有找到这样的工具。
I need to use custom filters, so I need to convert some long log4j.properties files to log4j.xml.
Is anyone aware of a tool to do this, or willing to contribute one they have used? Searching has thus far turned up no such tool.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我也需要这样做,但找不到工具。手动迁移数十个 log4j.properties 并不是一个令人满意的选择。因此,我开发了一个可以做到这一点的工具,并将其发布给其他人使用。
http://code.google.com/p/log4j-properties-converter/
这有点粗糙,但是对我给它的 log4j 属性起到了作用,所以任何问题都会将它们记录在问题跟踪器上。希望您觉得它有用。
I needed to do this as well, but couldn't find a tool. Migrating by hand dozens of log4j.properties was not a palatable option. So, I bashed together a tool that can do it and released it for others to use.
http://code.google.com/p/log4j-properties-converter/
It's a bit rough but did the trick for the log4j properties I gave it, so any problems log them on the issue tracker. Hope you find it useful.
以下内容可能对您有帮助。 Log4j 的创建者 Ceki Gülcü 启动了另一个名为 logback 的记录器项目,他提供了一个 log4j.properties 文件到 logback 的 xml 配置文件的在线翻译器。看起来 log4j.xml 和 logback.xml 的配置文件模式非常接近。
至少它应该生成可以轻松转换为 log4j.xml 格式的内容。
为了您的方便:这是 log4j 文档中的示例 log4j.properties 文件。只需将其粘贴到翻译器中并检查输出:
Here is something that may help you. Ceki Gülcü, the creator of log4j, started another logger project named logback, and he provides an online translator for log4j.properties files to xml config files for logback. It looks like the configuration file schemas of log4j.xml and logback.xml are pretty close.
At least it should produce something that can easily be converted to the log4j.xml format.
For your convenience: here's a sample log4j.properties file from the log4j documentation. Just paste it into the translator and check the output:
迟到的答案,但现在 class 提供从 log4jv1 .properties 到 log4jv2.xml 的批量(递归)转换配置。
来自 javadocs:
为了转换在给定路径中递归找到的所有名为
log4j.properties
的文件:下载 二进制分发版并将其解压缩到文件夹中(例如
bin
),运行:
Late answer, but nowadays a class named
Log4j1ConfigurationConverter
from the log4j bridge API offers batch(recursive) conversion from log4jv1 .properties to log4jv2.xml config.From the javadocs:
In order to convert all files named
log4j.properties
found recursively in a given path:Download the binary distribution from Log4j's site and unzip it in a folder (e.g.
bin
),Run:
想必您必须有很多需要转换的属性文件。当我想切换到 xml 时(很多年前),我找不到太多文档。我确实在 log4j 发行版中找到了非常有用的示例 xml 文件。
Presumably you must have a lot of properties files you need to convert. When I wanted to switch to xml (many years ago) I couldn't find much documentation. I did find sample xml files in the log4j distribution which were very useful.
最近使用 https://github.com/balent/Log4j-Convert-Configuration 来将 log4j.xml 文件转换为 log4j.properties 文件(我必须使用一个古老的 jar 来明确查找 log4j.properties)。配置允许采用两种方式:xml 到属性或属性到 xml。
从 https://github.com/balent/Log4j-Convert-Configuration/blob/master/binaries/full-with-dependencies/log4j-convert-full.jar 然后只需键入:
将其保留为开这里供将来的我找到。
Recently used https://github.com/balent/Log4j-Convert-Configuration to convert a log4j.xml file to a log4j.properties file (an ancient jar I had to use was explicitly looking for log4j.properties). The configuration allows going both ways: xml to properties OR properties to xml.
Download the binary build from https://github.com/balent/Log4j-Convert-Configuration/blob/master/binaries/full-with-dependencies/log4j-convert-full.jar and then just type:
Leaving this on here for future me to find.