Log in Tomcat and WebLogic (log4j) configuration Series III (log file storage path) __web

Source: Internet
Author: User
Tags log4j
Preface

I've been saying, how to read the Log4j profile log4j.properties.

The next discussion is: How to set the path of the log file created in log4j.

Tomcat's okay. For complex WebLogic, this is how to set the path, because it doesn't understand how to press the war file.

In the last article

Also mentioned in the log (log4j) configuration series (WebLogic application log4j) in Tomcat and WebLogic , if there is no configuration path, Logfile.log is also placed in the Base_domain directory by default.

Of course you configure an absolute path, but this is definitely not recommended.


You can set the relative path through ${param}/logfile.log.

In the Java Fetch System variables (environment variables and settings variables) , it is mentioned that log4j configuration can configure system variables.

Based on this, there are 2 ways to configure the relative path of the log4j.


method One: set the LOG_DIR system variable through the servlet initialization init () method

The variable name of this system can be arbitrarily taken, just make sure that the name of the variable used in the Init method and log4j is consistent.

System.setproperty ("Log_dir", "c:\\oracle\\middleware\\user_projects\\domains\\base_domain\\logs");

Of course, the Log_dir configured here cannot use an absolute path.

Can be passed Getservletcontext (). Getrealpath ("/"); And so on some of these methods to navigate to some relative paths.


Of course, this configuration can also be directly set in the configuration file Log4j.appender.logfile.File

            String logFile = spath+ "/" + Ps.getproperty ("Log4j.appender.logfile.File");
            Ps.setproperty ("Log4j.appender.logfile.File", logfile);
            Propertyconfigurator.configure (PS);


method Two: Through server environment variables

To deal with the inconvenience of a method, you also need to get some paths through the API.

Is it possible to directly use the already initialized system variables inside the Web server? Of course it can.

In the Windows environment, in the WebLogic. cmd file, there are
Set Java_properties=-dplatform.home=%wl_home%-dwls.home=%wls_home%-dweblogic.home=%wls_home%

-D variables for such a setting are written to the system variable.

So the above example uses ${platform.home} directly; ${wls.home} is OK.


In Tomcat, there are similar ${catalina.home} ...

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.