title: Writing to a log file using log4j
body: <p>I have a problem and an uncertainty relating to using Log4j.</p>
  
  <ol>
  <li>I can't write the log to a file. I only get a warning that says:</li>
  </ol>
  
  <p><code>log4j:WARN No such property [file] in org.apache.log4j.ConsoleAppender.</code></p>
  
  <p>Logging to console works fine.</p>
  
  <ol>
  <li>I want to store the log file outside the context root. In this case, would I hard code the absolute path into the properties file? Sorry if that's a dumb question.</li>
  </ol>
  
  <p><strong>Log4j.properties</strong></p>
  
  <pre><code># Root logger option
  log4j.rootCategory=INFO, file, stdout
  
  # Direct log messages to stdout
  log4j.appender.file=org.apache.log4j.FileAppender
  log4j.appender.file.File=/Users/me/Documents/apache-tomcat-7.0.34/wtpwebapps/my_app/log.txt
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  </code></pre>
  
  <p><strong>LogInit.java</strong></p>
  
  <pre><code>String root = Environment.getRootDirectory(getServletContext());
      String propertiesUri = root + propertiesUriParameter;
      File propertiesFile = new File(propertiesUri);
      if (!propertiesFile.exists())
      {
          System.out.println("Initializing log4j with: " + propertiesUri);
          PropertyConfigurator.configure(propertiesUri);
      }
  </code></pre>