log4j log file linux/mac/windows Common storage location Settings __linux

Source: Internet
Author: User
Tags solr log4j
Category configuration in Log4j1/log4j2 and log output location (Windows and Linux common log output location) Category: Server Technology | Tags: windows| date: 2015-08-13 02:00:10 I. Scenarios and Requirements

Let's say I have 3 separate project (for the time being associated with Maven, and of course not maven), one is the infrastructure that provides the public service, one is the persister that provides the storage, the other is the searcher that provides the search, All the classes that provide the underlying service, such as Dateutils, Tool classes such as Httputils are located under the directory Com.chuanliu.platform.activity, and all classes that provide the storage service are located under the Com.chuanliu.platform.activity.persist directory, and all classes that provide the search service are located in the CO M.CHUANLIU.PLATFORM.ACTIVITY.SOLR under.

Now the project needs to have a log file called Full.log, need to record all the logs, whether under the infrastructure, or under the Persister, or under the Seracher, In addition, a log file called Solr.log is required to record all the logs that occur under the search directory. Of course in the future should also put the log in the Searcher directory in the Searcer.log.

In addition, you should support different log output locations based on different deployment environments, because Windows and Linux have different directory structures.

two, whether log4j1 or LOG4J2, you can use the following configuration:

Log4j.rootlogger = Info Log4j.debug = False log4j.category.com.chuanliu.platform.activity = info, full, stdout #The child Logger Appender would not inherit the parent logger ' appender, or the logs would be output twice in the file Log4j.additiv Ity.com.chuanliu.platform.activity.platform.activity = False LOG4J.CATEGORY.COM.CHUANLIU.PLATFORM.ACTIVITY.SOLR = info, Solr LOG4J.ADDITIVITY.COM.CHUANLIU.PLATFORM.ACTIVITY.PLATFORM.ACTIVITY.SOLR = False ###### activity full log:
Contains all of the log #full log4j.appender.full = Org.apache.log4j.DailyRollingFileAppender Log4j.appender.full.File = ${logfile.location}/full.log Log4j.appender.full.DatePattern = '. '
Yyyy-mm-dd log4j.appender.full.layout = org.apache.log4j.PatternLayout Log4j.appender.full.layout.conversionPattern =%d [%t]%-5p%c{1}-%m%n Log4j.appender.full.ImmediateFlush = True log4j.
Appender.full.append = True ##### #activity full log ##### #activity SOLR log:only contain the log in searcher#### #solr Log4j.appendER.SOLR = Org.apache.log4j.DailyRollingFileAppender Log4j.appender.solr.File = ${logfile.location}/solr.log Log4j.appender.solr.DatePattern = '. '
Yyyy-mm-dd log4j.appender.solr.layout = org.apache.log4j.PatternLayout Log4j.appender.solr.layout.conversionPattern =%d [%t]%-5p%c{1}-%m%n Log4j.appender.solr.ImmediateFlush = True log4j. Appender.solr.append = True ##### #activity SOLR log # Console output ... log4j.appender.stdout=org.apache.log4j.cons
Oleappender Log4j.appender.stdout.layout=org.apache.log4j.patternlayout Log4j.appender.stdout.layout.conversionpattern=[%d][%p]%t:%m%n # Log SQL for mybatis log4j.logger.mybatis =trace org. Springframework.web=debug

 

after testing, you will find that all the logs are in the Full.log, and only the log output under COM.CHUANLIU.PLATFORM.ACTIVITY.SOLR is in Solr.log.

In addition, for the output location of the log, ${logfile.location}, We can customize the values of logfile.location in the configuration files of different environments, for example, in dev.properties that represent the local environment, define Logfile.location=c://logs

In the qa.properties of the test environment, define the Logfile.location=/usr/local/var/logs, and also define the same values in the production environment as: logfile.location=/usr/local/var/ Logs, this will generate different log files in different environments under different paths.

In fact, after testing, not so troublesome, we can unify the Windows and Linux log output to the same place, that is, we can unify the output set to/usr/local/var/logs, such a setup in Linux, we can understand , but in Windows, it may not be so well understood that in Windows,/usr/local/var/log has 2 layers of meaning:

1. If you are a method of classes that perform these log outputs in eclipse, you will create a directory/usr/local/var/log on the disk where workspace resides, such as e disk, and output Full.log and Solr.log.

2. If the output of the execution log is applied to Tomcat, there is a directory/usr/local/var/log on the disk where Tomcat resides, such as the D disk, and Full.log and Solr.log are exported, even if the tomcat is started in eclipse , when Tomcat's Wtpapps directory is in the directory where Eclipse is located, such as e disk, but the actual tomcat used is in the D disk, the same log file is exported in/usr/local/var/logs.

From: http://www.tools138.com/create/article/20150813/020010118.html

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.