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 8384637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:27:14+00:00 2026-06-09T17:27:14+00:00

I’m running a web app under tomcat and I’ve configured logging like this (via

  • 0

I’m running a web app under tomcat and I’ve configured logging like this (via a contextInitialized hook):

    Logger rootLogger = Logger.getLogger("");
    String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    FileHandler logHandler = new FileHandler(
        "myapp_" + date + "_%u.log",
        524288000, // 500 MB max size
        1, // one log file at a time
        true // if it exists: append, don't overwrite
    );
    Level defaultLevel = Level.INFO;
    logHandler.setFormatter(new XMLFormatter());
    logHandler.setLevel(defaultLevel);
    for (Handler h : rootLogger.getHandlers()) {
        rootLogger.removeHandler(h);
    }
    rootLogger.setLevel(defaultLevel);
    rootLogger.addHandler(logHandler);

Unfortunately the logs don’t get created under /var/log. They get created in /var/lib/tomcat6/ like /var/lib/tomcat6/myapp_2012-08-13_0.log. I’d like to change it to /var/log/myapp/ like: /var/log/myapp/myapp_2012-08-13_0.log I don’t see anything I can set on the FileLogger to make this happen. Am I missing something obvious, or is there a way to achieve it?

  • 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-06-09T17:27:15+00:00Added an answer on June 9, 2026 at 5:27 pm

    You could use a JVM property to prepend to the file name. In the below sample pass in something like -Dlog_directory=C:\logs

    package sample;
    
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.logging.FileHandler;
    import java.util.logging.Handler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.logging.XMLFormatter;
    
    import org.apache.commons.lang.StringUtils;
    
    public class stackoverflow11937181 {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            Logger rootLogger = Logger.getLogger("");
            String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            String logDirectory = System.getProperty("log_directory");
            String logFile = (logDirectory == null ? StringUtils.EMPTY : logDirectory) + "/myapp_" + date + "_%u.log";
            try {
                FileHandler logHandler = new FileHandler(logFile, 524288000, // 500 MB max size
                        1, // one log file at a time
                        true // if it exists: append, don't overwrite
                );
                Level defaultLevel = Level.INFO;
                logHandler.setFormatter(new XMLFormatter());
                logHandler.setLevel(java.util.logging.Level.FINE);
                for (Handler h : rootLogger.getHandlers()) {
                    rootLogger.removeHandler(h);
                }
                rootLogger.setLevel(defaultLevel);
                rootLogger.addHandler(logHandler);
    
            }
            catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            rootLogger.log(Level.FINE, "sample");
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.