Log4j打印整个网页,响应和图像

时间:2012-11-08 11:50:09

标签: java web-services log4j

我不知道这是否已经发生在任何人身上,我已经搜索过并且还没有找到任何解决方案,Log4J也打印了所有的网站内容和响应代码和图像..

][0xaf][0xac]aSn[0xbc][0xe4][0x85][0xbf]i[0x1]p[0xad][0x82])O[0xbb]"[0xd7]u[0x1a][0xcc]Q[0x87][0x98][0xeb][0xcb]+[0xf9][0x1e][0xa5][0xfd][0x83]l[0xb7][0xd6][0xb2][0xb4]RL2[0xe][0xc3]}[0xc][0xff]][0xf5][0xe3][0xad][0xda][0x83]a[0x91][\r]g[0x9a][0x9b][0xe6][0xeb][0xb7][0x80][0x8b][0xfb][0x12]:[0x14]3C[0xad][0xe5]JNN[0xc0][0xd3][0xb6]%[0xe1]_[0xd0]z([0xa4]K[0x90][0xcd][0xd8][0xcb][0xdb][0xfe][0xcc][0xf0][0x17][0xb0][0xab]f[0x7][0xc5][0x84][0xb6]=[0x91]6[0xc1]=r[0x86][0xc3]}^D4<[0xa0][0x8a][0x6]>[0xed][0xa7][0xa4][0xec]1[0x4][0x9b][0xdc][0xa5]Y*[0xa3][0xaa][0x13][0x9f]R[0x9e][\r][0x81][0xb0][0x99][0xcd]J[0xf8][0x12][0x88][0xfa]o[0x96][0xdd][0x92][\r][0xd0][0xbd][0xb8]du[0xa3]>[0xf5][0xe2][0xaa][0xb][0xd3][0xd1][0xad]0[0xf6]6[0xef]s[0x8b][0xcf][0xd0][0xd0][0xa8](0[0xa5]x[0x9]V[0x13][0xcb][0x1]<[0x83c[0xf1]A[0xfa]f[0xfa][0x97]SM[0xf3][0xc][0x91][0xe8][0x96][0x16]i[0xbf]"b[0xab][0x95]l[0x11]e[0xbd]_[0xe8] [0xe9][0xb0]A''[0xc7][0x9e][0x81][0xa7]"*[0x0]a[0xb][0xac]R[0x9f]x[0xcc][0x1c][0xc9][0xc0][0xcf][0xd8]J[0x19][0xa3]>e[0xde][0x99][0xcf]T[0xc2]{r[0xc5][0x84]r*[0xa4]8[0xe]"
2012-11-08 11:23:40,728 DEBUG - >> "[\r][\n]"
2012-11-08 11:23:40,728 DEBUG - >> "--"
2012-11-08 11:23:40,728 DEBUG - >> "Rn8Y3anzO4BsiuQ8eSDsFYPH8Yef21FYHm"
2012-11-08 11:23:40,728 DEBUG - >> "[\r][\n]"
2012-11-08 11:23:40,728 DEBUG - >> "Content-Disposition: form-data; name="
2012-11-08 11:23:40,728 DEBUG - >> """
2012-11-08 11:23:40,728 DEBUG - >> "description"
2012-11-08 11:23:40,728 DEBUG - >> """
2012-11-08 11:23:40,728 DEBUG - >> "[\r][\n]"

2012-11-08 11:23:40,728 DEBUG - >> "Rn8Y3anzO4BsiuQ8eSDsFYPH8Yef21FYHm"
    2012-11-08 11:23:40,728 DEBUG - >> "--"
    2012-11-08 11:23:40,728 DEBUG - >> "[\r][\n]"
    2012-11-08 11:23:40,728 DEBUG - Request body sent
    2012-11-08 11:23:41,481 DEBUG - << "HTTP/1.1 200 OK[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - << "HTTP/1.1 200 OK[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - << "Server: Apache-Coyote/1.1[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - << "Content-Type: text/html;charset=UTF-8[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - << "Transfer-Encoding: chunked[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - << "Date: Thu, 08 Nov 2012 11:14:44 GMT[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - << "[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - Completed Getting Page
    2012-11-08 11:23:41,481 DEBUG - << "5"
    2012-11-08 11:23:41,481 DEBUG - << "0"
    2012-11-08 11:23:41,481 DEBUG - << "[\r]"
    2012-11-08 11:23:41,481 DEBUG - << "[\n]"
    2012-11-08 11:23:41,481 DEBUG - << "{"status":"OK","code":"unspecified","message":"successfully uploaded procedure"}"
    2012-11-08 11:23:41,481 DEBUG - << "[\r]"
    2012-11-08 11:23:41,481 DEBUG - << "[\n]"
    2012-11-08 11:23:41,481 DEBUG - << "0"
    2012-11-08 11:23:41,481 DEBUG - << "[\r]"
    2012-11-08 11:23:41,481 DEBUG - << "[\n]"
    2012-11-08 11:23:41,481 DEBUG - << "[\r]"
    2012-11-08 11:23:41,481 DEBUG - << "[\n]"
    2012-11-08 11:23:41,481 DEBUG - << "[\r][\n]"
    2012-11-08 11:23:41,481 DEBUG - Resorting to protocol version default close connection policy
    2012-11-08 11:23:41,482 DEBUG - Should NOT close connection, using HTTP/1.1
    2012-11-08 11:23:41,482 DEBUG - Releasing connection back to connection manager.

我正在使用apaches的httpClient的PostMethod()和GetMethod()..来将数据从一个servlet发送到另一个servlet。 我不打印这些。 log4j自己打印这些。我不明白。并且日志文件的大小约为50到100 MB。

我的Log4j配置: -

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

   <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
      <param name="Threshold" value="INFO" />
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d %-5p  [%c{1}] %m %n" />
      </layout>
   </appender>
   <appender name="DRFA" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="/home/server/webSpecimen.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <param name="Append" value="true" />
    <param name="Threshold" value="DEBUG" />

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

   <root>
                <level value="DEBUG" />
                <appender-ref ref="DRFA" />
        </root>

</log4j:configuration>

3 个答案:

答案 0 :(得分:0)

这可能会对你有所帮助 http://en.wikipedia.org/wiki/Log4j

正如我所看到的,您已将其设置为调试级别,尝试将其置于INFO,WARN或ERROR级别。有关详细信息,请阅读以上链接。

由于

答案 1 :(得分:0)

我认为这不是log4j的错。我认为HttpClient代码库只是在DEBUG级别进行大量日志记录。解决方案是将根记录器级别更改为INFO以减少日志记录...或者更有选择地为HttpClient正在使用的记录器执行此操作。 (不幸的是,你的appender的模式不包括记录器名称......)


  

..但为什么log4j会打印图像和整个网站...

因为这是你的log4j配置告诉它的事情:

  • 阅读log4j introduction,特别是有关如何编写配置文件的部分。
  • 更改您的配置,以便为生成这些日志消息的特定记录器使用不同的日志级别。
  

我刚刚在一个类中注释掉所有日志,其中打印了所有不需要的日志......

这是错误的做法。您需要了解log4j如何决定记录什么以及不记录什么。阅读文档。随机评论一些东西无济于事。

  

是因为我使用的是HttpClient 3.1,当前版本是4.2.2 ..

没有。这不是原因。

答案 2 :(得分:0)

log4j中的

将DEBUG更改为INFO并查看。

Log4j中的

有级别层次结构

可以为记录器分配级别。可能的级别集合,即:learn here

TRACE,
DEBUG,
INFO,
WARN,
ERROR and
FATAL

当您调试时,它将打印DEBUG和所有波纹管日志级别。如果你输入INFO,它将打印INFO和所有波纹管级别的日志。

通常情况下,如果您在生产模式preper中运行以放置ERROR

更新后的this

将此添加到log4j xml并尝试

<logger name="httpclient.wire" additivity="false" >
  <level value="INFO" />
  <appender-ref ref="consoleAppender"/>
  <appender-ref ref="fileAppender"/>
  </logger>