Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:24:32+00:00 2026-05-25T21:24:32+00:00

I have log4j.xml configuration like this: <appender name=MyAppenderclass=org.apache.log4j.DailyRollingFileAppender> <param name=File value=/logs/custom/my.log/> … </appender> However

  • 0

I have log4j.xml configuration like this:

<appender name="MyAppender"class="org.apache.log4j.DailyRollingFileAppender">   
     <param name="File"     value="/logs/custom/my.log"/>
...  
 </appender>

However the root directory of my file are the same for a lot of appender. Is there a way to defined “/logs/custom/” as a variable and reused it in all of my appender.

Thanks,

Sean

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:24:32+00:00Added an answer on May 25, 2026 at 9:24 pm

    UPDATE: The original answer applies to Log4j 1.x

    Log4j 2.x has much richer support for properties in configuration file, see the Log4j manual about Configuration with properties.

    Log4j 1.x (the original answer):

    The only way to achieve something similar when you are using log4j.xml is to set a system property at startup and then reference that from your log4j.xml.

    At startup, you set your system property:

    java -Dlog_dir=/var/logs/custom     com.yourorg.yourapp.Main
    

    Or set it programmatically at runtime (before initializing Log4j):

    System.setProperty("log_dir", "/var/logs/custom")
    

    Then you can reference it like this:

    <appender name="MyAppender"class="org.apache.log4j.DailyRollingFileAppender">   
         <param name="File" value="${log_dir}/my.log"/>
         ...  
    </appender>
    

    Or in properties file, like this:

    log4j.appender.MyAppender.File = ${log_dir}/my.log
    

    Source: I got inspiration for this answer from Using system environment variables in log4j xml configuration.

    Also, if you are running under Tomcat, you can use ${catalina.home} variable, like this:

    <appender name="MyAppender"class="org.apache.log4j.DailyRollingFileAppender">   
         <param name="File" value="${catalina.home}/logs/my.log"/>
         ...  
    </appender>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following log4j.xml configuration: <log4j:configuration> <appender name = CONSOLE class = org.apache.log4j.ConsoleAppender>
I have a java app that uses log4j. Config: log4j.rootLogger=info, file log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=${user.home}/logs/app.log log4j.appender.file.layout=org.apache.log4j.PatternLayout
I am currently watching an XML file from log4j output. I have a custom
I have an xml configuration file which works fine in Java, and I'm trying
I am writing Perl script. In that I have to read log4j.xml file from
I have a custom java log4j appender class like com.xyz.abc.MyCustomAppender. I am able to
I am trying to get log4j working using xml configuration. I have log4j.xml added
I have the following in log4j.xml file, when I run my application. Only error
Suppose i have a configuration file like the following to start my application. How
i have little question, my log4j.xml configuration is listed below <?xml version=1.0 encoding=UTF-8 ?>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.