Completely solve the problem of Tomcat6 after joining LOG4J in the Linux platform garbled __linux

Source: Internet
Author: User
Tags log log log4j

A very distressing event occurred during the recent development process: tomcat8+jdk1.8 Debugging in Windows is fine, tomcat6+jdk1.6 test environment is OK, but Linux (tomcat6+jdk1.6) distributed to the production environment, Use soon the user reflects the input of the Chinese all garbled!

Can be fortunate to have to do the backup, so hurriedly restore the backup, then wrote a small test test.jsp dropped into the Linux environment:

<% @page import= "org.apache.commons.logging.LogFactory"%> <% @page import= "Org.apache.commons.logging.Log" %> <%/*--------------------------------------------------------------------program:sar920l1-created:22/ oct/2008 by CSMISWFL modify:26/dec/2008 by Dgmishxw modify:05/jan/2009 through CSMISWFL modify:14/jan/2010 by DGMISL FB *--------------------------------------------------------------------*/%> <%@ include file= "sardef.jsp"%&
Gt <%@ include file= "common/alco_lib.jsp"%> <%@ include file= "common/alco_header.jsp"%> <script "type="
  Text/javascript "src=" js/jq.js "></script> <%//*//Database Access Connection w_conn = null;
  Statement w_stmt = null;
  ResultSet w_rs = null;
  String lvname= "";
  String Pvstaffname=x01getparameter (C_para, "staffname");
  if (pvstaffname==null) {pvstaffname= "";
  Log log = Logfactory.getlog ("test");
  Log.info ("Input value:" +pvstaffname); try {w_conn = x60getcOnnection ();
    w_stmt = W_conn.createstatement (resultset.type_scroll_insensitive,resultset.concur_read_only);
    if (!pvstaffname.equals ("")) {X62executesql (w_stmt, "Update test set staffname= '" +pvstaffname+ "");
    } w_rs=x61executequery (W_stmt, "SELECT * FROM Test limit 1");
    W_rs.next ();
    Lvname=w_rs.getstring ("Staffname");
  W_rs.close ();
   
}finally {x63closeconn (W_conn, w_stmt, w_rs);} 
%> <div> Submit Value:<%=pvstaffname%><br/> Database value: <%=lvname%> </div> <form action= "./test.jsp" method= "POST" > <label>update name:</label> <input name= "Staffname" Value= "<%=lvName%>"/> <input type= "Submit"/> </form>

In the new Web App, in the test.jsp page input Chinese, input value is garbled, all kinds of elimination finally found that the original is log4j to blame. Later specified log4j log output encoding or not, inadvertently, change the log level to info and try again, OK. Just began to think hand mistake, and then change to debug, garbled. Change to info normal ... It's a wonderful flower. But under the Linux tomcat8+jdk1.8 is completely no problem, this is log4j bug or Tomcat6 bug?!

posted this log4j configuration, compatible with TOMCAT6 Chinese/log output is also Chinese, the project code is utf-8.

### Logger configuration ### #配置根logger log4j.rootlogger=info,stdout,rollingappender #配置子logger: Org.lavasoft ( The log of the class in the Org.lavasoft package uses this logger without specifying a logger name #log4j. Logger.org.lavasoft=error,file #配置子logger: o Rg.lavasoft.test (The log of the class in the Org.lavasoft.test package uses this logger without specifying a child logger name) #log4j. Logger.org.lavasoft.test=error, File1,stdout log4j.appender.syslog.encoding=utf-8 log4j.appender.logfile.encoding=utf-8 ### Direct log messages to
STDOUT ### (standard terminal output) #控制台输出 Log4j.appender.stdout=org.apache.log4j.consoleappender #自定义输出布局
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout #输出的格式 Log4j.appender.stdout.layout.conversionpattern=%d{absolute}%5p%c{1}:%l-%m%n ### Direct messages to file Ttt.log ###
(Input to the configuration of the file Ttt.log) #输出到滚动文件 Log4j.appender.rollingappender=org.apache.log4j.dailyrollingfileappender #输出文件最大为10M
LOG4J.APPENDER.ROLLINGAPPENDER.MAXFILESIZE=2MB Log4j.appender.rollingappender.threshold=info #输出文件最大序号为10 log4j.appender.rollingappender.maxbackupindex=10 #输出文件路径 log4j.appender.RollingApPender.
File=/live/logs/dgsar #log4j. appender.appender2.datepattern= ' _ ' yyyy-mm-dd '. Log ' Log4j.appender.rollingappender.datepattern= '. '
YYYY-MM-DD #自定义输出布局 log4j.appender.rollingappender.layout=org.apache.log4j.patternlayout #输出格式
 
 log4j.appender.rollingappender.layout.conversionpattern=%d%-5p [%t] (%13f:%l)%3x-%m%n

log4j version of Project: log4j-1.2.17
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.