tomcat log and log4j log garbled

Linux system character encoding: http://www.cnblogs.com/zhzhao/p/4516997.html
linxu configuration file: http://blog.chinaunix.net/uid-14735472-id-4305151.html
Generally in our windows When developing the program, the GBK encoding format can be displayed on the Windows system,
but in the Linux environment, garbled characters appear. If this problem occurs, check the following 3 steps:
1. Check the log encoding configuration
log4j.properties:
log4j.appender.A = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.A.Threshold=INFO
log4j.appender.A.File=${catalina.home}/logs/test/log
log4j.appender.A.DatePattern=yyyy-MM-dd'.log'
log4j.appender.A.layout=org.apache.log4j.PatternLayout  
log4j.appender.A.Encoding=UTF-8
log4j.appender.A.layout.ConversionPattern=[FH_sys]  %d{yyyy-MM-dd HH\:mm\:ss} %5p %c{1}\:%L \: %m%n



logback.xml:
<appender name="file"
         class="ch.qos.logback.core.rolling.RollingFileAppender">
         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
             <FileNamePattern>${catalina.home}/logs/test/%d{yyyy-MM-dd}.log</FileNamePattern>
             <MaxHistory>30</MaxHistory>
         </rollingPolicy>
         <encoder>
             <pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern>
              <charset>UTF-8</charset>
         </encoder>
</appender>


2. Check tomcat configuration
server.xml
 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding='UTF-8'/>	
     
3. Check the server encoding configuration
[email protected]:~> locale
LANG=zh_CN.GBK
LC_CTYPE="zh_CN.GBK"
LC_NUMERIC="zh_CN.GBK"
LC_TIME="zh_CN.GBK"
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=zh_CN.GBK


Modify the Linux character set:
vim /etc/profile
export LC_ALL=zh_CN.UTF-8
:wq

Load the new configuration:
source /etc/profile
[email protected]:~> locale
LANG = zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=zh_CN.UTF-8

This is the global configuration code set. Sometimes the configuration of LANG or LC_ALL in the user's configuration file needs to be modified accordingly. The .bashrc and .profile files in
the home directory can be used to
restart the service.
Attachment: The difference between linux configuration files
/etc/profile, /etc/bashrc is the system global environment variable setting ~/.profile, ~/.bashrc private environment variable setting in the user's home directory When you log in to the system and get a shell process , there are three steps to read the environment configuration file:
1. First read the global environment variable configuration file /etc/profile, and then read additional set documents according to its content, such as /etc/profile.d and /etc /inputrc;
2 Then according to different user accounts, go to their home directory to read ~/.bash_profile, if this can't be read, read ~/.bash_login, if this can't be read, then read ~/.profile, this The settings of the three documents are basically the same, and the reading has priority;
3. Then read ~/.bashrc according to the user account. As for the difference between ~/.profile and ~/.bashrc, both have the function of personalization and customization ~/.profile can set the user-specific path, environment variables, etc. It can only be executed once when logging in. ~/.bashrc is also a user-specific configuration file, which can set the path, command alias, and each time Execution of the shell script will use it once.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326483955&siteId=291194637