java 在 jboss 中禁用 Axis log4j 日志记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1243768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:47:18  来源:igfitidea点击:

Disable Axis log4j logging in jboss

javajbosslog4jaxis

提问by FrankS

I have small application that is uploading pictures to another website via webservice. My current problem is, that Axis is logging the whole xml message (including the binary data of the picture!) via STDOUT and I can't seem to figure out, how to disable it.

我有一个通过网络服务将图片上传到另一个网站的小应用程序。我当前的问题是,Axis 正在通过 STDOUT 记录整个 xml 消息(包括图片的二进制数据!),我似乎无法弄清楚如何禁用它。

My log4j settings for jboss (jboss-log4j.xml) includes an appender for normal STDOUT Info loggings, and I tried to disable axis with different category settings:

我的 jboss (jboss-log4j.xml) 的 log4j 设置包括一个用于正常 STDOUT 信息日志记录的附加程序,我尝试禁用具有不同类别设置的轴:

<appender name="STDLOG" class="org.jboss.logging.appender.RollingFileAppender">
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
  <param name="File" value="${jboss.server.log.dir}/myapplication.log"/>
  <param name="Append" value="true"/>
    <param name="MaxFileSize" value="5MB"/>
    <param name="MaxBackupIndex" value="10"/>

    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
  </layout>
</appender>

using this setting for STDOUT:

将此设置用于 STDOUT:

<category name="STDOUT">
  <priority value="DEBUG"/>
  <appender-ref ref="STDLOG"/>
</category>

I tried these category settings without any change in the result:

我尝试了这些类别设置,结果没有任何变化:

<category name="log4j.logger.org.apache.axis" additivity="false">
  <priority value="ERROR"/>
</category>

<category name="org.apache.axis">
  <priority value="ERROR"/>
</category>

Some sample log output looks like this:

一些示例日志输出如下所示:

2009-08-07 10:29:43,911 INFO  [STDOUT] (http-127.0.0.1-8080-1) =======================================================
= Elapsed: 2190 milliseconds
= In message: <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <addVehicleImage xmlns="urn:VMgrWebService">
   <id xmlns="">APP-T4QKR3U</id>
   <idType xmlns="">chiffre</idType>
   <data xmlns="">9j4AAQSkZJRgABAQAAAQABAAD2wBDAAUDBAQEAwUEBAQFB
     QUGBww0TDMnrXAfKlLjnNJZcciiAOtqk9NG99qhZJKuyYq5k3G
     8P2bVSOpT7rVddRP2Z/yqidRuMMKaO2CXRQNWP2jfOo4S4Bo3W
   removed rest of image data...
     IBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGe1UqaZJJy0jSHPGQ
2009-08-07 10:29:43,927 INFO  [STDOUT] (http-127.0.0.1-8080-1) Upload result: true for image mypicture.JPG  

UpdateI checked the axis-1.4.jar and there is a file called simplelog.properties:

更新我检查了 axis-1.4.jar 并且有一个名为simplelog.properties的文件:

# Logging detail level,
# Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
org.apache.commons.logging.simplelog.defaultlog=info

Setting this to error within the jar, or as a category in jboss-log4j.xml didn't help at all.

将此设置为 jar 中的错误,或作为 jboss-log4j.xml 中的一个类别根本没有帮助。

Anyone any idea how I can turn off the Axis logging or at least set it to ERROR level?

任何人都知道如何关闭 Axis 日志记录或至少将其设置为 ERROR 级别?

Cheers
Frank

干杯
弗兰克

回答by Vineet Reynolds

This might be a bit late in the day, but the problem does not seem to be that logging itself is done in Axis (via System.out and Commons Logging), but rather that the LogHandleris present in the handler chain. That is how the elapsed time is getting logged.

这可能有点晚了,但问题似乎不在于日志本身是在 Axis 中完成的(通过 System.out 和 Commons Logging),而是LogHandler存在于处理程序链中。这就是记录经过的时间的方式。

You can disable this handler from the Axis configuration file(s) - server-config.wsdd and/or client-config.wsdd, depending on whether you are using Axis as a server or a client.

您可以从Axis 配置文件中禁用此处理程序- server-config.wsdd 和/或 client-config.wsdd,具体取决于您将 Axis 用作服务器还是客户端。

The reason why you are seeing messages in your console is probably due to the LogHandler.writeToConsole property being set to true. If you set LogHandler.writeToConsole to false, it should write into a file as defined by the LogHandler.fileName property. By default, the file name is axis.log.

您在控制台中看到消息的原因可能是由于 LogHandler.writeToConsole 属性设置为 true。如果您将 LogHandler.writeToConsole 设置为 false,它应该写入由 LogHandler.fileName 属性定义的文件。默认情况下,文件名为axis.log。

回答by FrankS

Ok, after trying to find a better solution, the only real way was to check the old legacy code and turn all System.out calls into real logging statements (much better anyway), and then simply filter the remaining STDOUT messages into a different log file.

好的,在尝试找到更好的解决方案之后,唯一真正的方法是检查旧的遗留代码并将所有 System.out 调用转换为真正的日志记录语句(无论如何要好得多),然后简单地将剩余的 STDOUT 消息过滤到不同的日志中文件。

One of the main reasons seems to be Jboss itself. This discussionfrom the axis2 mailing list explains why: Ahh, but you didn't mention you are using jboss! It pretty much forces you to use their parent log4 config . Ignore the axis2 logging in this case, and see:

主要原因之一似乎是 Jboss 本身。这个来自axis2邮件列表的讨论解释了为什么:啊,但你没有提到你正在使用jboss!它几乎迫使您使用他们的父 log4 config 。在这种情况下忽略axis2日志记录,并查看:

~/jboss/server/default/conf/log4j.xml

~/jboss/server/default/conf/log4j.xml

There you have to limit the categories. For example, you have:

在那里你必须限制类别。例如,您有:

<category name="org.apache">
  <priority value="INFO"/>
</category>

You could leave that as is and just get your logs out of server.log .

您可以保持原样,只需将日志从 server.log 中取出即可。

I tried setting the category, without success. I assume this is because of differences between axis and axis2. So the only solution left was to go the good coding way and just don't use STDOUT in your own code ;-)

我尝试设置类别,但没有成功。我认为这是因为轴和轴 2 之间的差异。因此,剩下的唯一解决方案是采用良好的编码方式,并且不要在您自己的代码中使用 STDOUT ;-)

回答by Vijay Kumar

It is very important to know which log4j.properties file or log4j.xml is being read. and as Matt pointed out, this is crucial in knowing why your tweaking efforts are not working.

了解正在读取哪个 log4j.properties 文件或 log4j.xml 非常重要。正如马特指出的那样,这对于了解为什么您的调整工作不起作用至关重要。

回答by matt b

First off, you'll want to check that your log4j configuration is actually the one being read - I recall that in the past, at least one axis jar (I think it may have been axis-ant.jar) was guilty of bundling their own log4j.properties. It may be that log4j is reading a different configuration file than yours, making your efforts at tweaking the configuration pointless!

首先,您需要检查您的 log4j 配置是否确实是正在读取的配置 - 我记得在过去,至少有一个轴 jar(我认为可能是axis-ant.jar)因为捆绑了自己的 log4j.properties 而感到内疚。可能是 log4j 正在读取与您不同的配置文件,使您调整配置的努力毫无意义!

You can enable the system properties -Dlog4j.debugto have log4j print to standard out which configuration file is being read. If necessary, you can use -Dlog4j.configuration=<file>to point to your own file.

您可以启用系统属性-Dlog4j.debug以将 log4j 打印到标准输出正在读取的配置文件。如有必要,您可以使用-Dlog4j.configuration=<file>指向您自己的文件。

Also, I don't think this is causing your issues, but why are you setting additivity to false?

另外,我不认为这会导致您的问题,但是您为什么将可加性设置为 false?

回答by Yishai

The problem is that Axis is not using Log4j to log that message, so attempting to change the log4j logging level on that class isn't relevant. Axis is using a System.out.println.

问题是 Axis 没有使用 Log4j 来记录该消息,因此尝试更改该类上的 log4j 日志记录级别是不相关的。Axis 正在使用 System.out.println。

The only thing I can think of (which is really not nice given the side effects) is to turn the STDOUT logging off altogether. Probably setting the priority to off will do.

我唯一能想到的(考虑到副作用确实不好)是完全关闭 STDOUT 注销。可能将优先级设置为关闭就可以了。

The only real solution is to fix Axis and patch the code to not pump the xml to System.out but rather use the logging mechanism instead - then you could control it.

唯一真正的解决方案是修复 Axis 并修补代码以不将 xml 泵送到 System.out 而是使用日志记录机制 - 然后您可以控制它。