Configure WEB application logs on a Linux server to print to a specified file

Source: Internet
Author: User


On the Linux server, configure the WEB application logs to print to the specified file server environment, which is RedHat Linux and runs Apache + Tomcat, the container runs a small e-commerce website of our company. The log information in the original project is printed directly with the Tomcat container to/tomcat/logs/catalina. in the out clause, the log is mixed with the log of the server itself, which is particularly difficult to see. Especially when there is a lot of log information, important information is always rushed out. I feel particularly uncomfortable. So I tried to solve this problem two months ago. The idea was to configure the log output mode for the application and redirect it to the specified log file, we can simply view the log files to understand possible problems during code running. The application used LOG4J to print the log information. After checking the relevant information, I decided to use Rolling File Appender. Because this method prints logs, when the log capacity reaches the specified value, for example, 100 MB will automatically regenerate a new file and back up the original 100 MB file, you can retain the log information on the server for a certain period of time, which is very helpful for server maintenance. Log4j in the project www.2cto.com. the properties configuration information is as follows: 01log4j. rootLogger = DEBUG, ROLLING_FILE02log4j.additivity.org.apache = true03 04log4j. appender. ROLLING_FILE = org. apache. log4j. rollingFileAppender05log4j. appender. ROLLING_FILE.Threshold = INFO06log4j. appender. ROLLING_FILE.File =/home/logs/server. log07log4j. appender. ROLLING_FILE.Append = true08log4j. appender. ROLLING_FILE.MaxFileSize = 100MB09 www.2cto.com log4j. appende R. ROLLING_FILE.MaxBackupIndex = 110log4j. appender. ROLLING_FILE.layout = org. apache. log4j. patternLayout11log4j. appender. ROLLING_FILE.layout.ConversionPattern = [framework] % d-% c-%-4r [% t] %-5 p % c % x-% m % n print the application log information directory/home/logs/server. log, In addition, after the configuration is complete, I found that besides the application logs will be printed to this file, the server logs and application logs are still printed to/tomcat/logs/catalina. out file. However, this does not affect our development. When we need to view the log information, we only need to view the/home/logs/server. log file.
 

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.