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 as RedHatLinux, and run Apache + Tomcat on it, the container runs a small e-commerce website of our company. The log information in the original project is directly followed by Tom...
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.
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.