Save This Page
Home » struts-1.3.9-src » examples.lf5 » InitUsingMultipleAppenders » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package examples.lf5.InitUsingMultipleAppenders;
   18   
   19   import org.apache.log4j.Logger;
   20   import org.apache.log4j.PropertyConfigurator;
   21   
   22   import java.io.IOException;
   23   import java.net.URL;
   24   
   25   /**
   26    * This example shows how to use LogFactor5 with other Log4J appenders
   27    * (In this case the RollingFileAppender).
   28    *
   29    * The following lines can be added to the log4j.properties file or a
   30    * standard Java properties file.
   31    *
   32    *   # Two appenders are registered with the root of the Category tree.
   33    *
   34    *   log4j.rootCategory=, A1, R
   35    *
   36    *   # A1 is set to be a LF5Appender which outputs to a swing
   37    *   # logging console.
   38    *
   39    *   log4j.appender.A1=org.apache.log4j.lf5.LF5Appender
   40    *
   41    *   # R is the RollingFileAppender that outputs to a rolling log
   42    *   # file called rolling_log_file.log.
   43    *
   44    * log4j.appender.R=org.apache.log4j.RollingFileAppender
   45    * log4j.appender.R.File=rolling_log_file.log
   46    *
   47    * log4j.appender.R.layout=org.apache.log4j.PatternLayout
   48    * log4j.appender.R.layout.ConversionPattern=Date - %d{DATE}%nPriority
   49    * - %p%nThread - %t%nCategory - %c%nLocation - %l%nMessage - %m%n%n
   50    * log4j.appender.R.MaxFileSize=100KB
   51    * log4j.appender.R.MaxBackupIndex=1
   52    *
   53    * To make this example work, either run the InitUsingMultipleAppenders.bat
   54    * file located in the examples folder or run it at the command line. If you
   55    * are running the example at the command line, you must ensure that the
   56    * example.properties file is in your classpath.
   57    *
   58    * @author Brent Sprecher
   59    * @author Brad Marlborough
   60    */
   61   
   62   // Contributed by ThoughtWorks Inc.
   63   
   64   public class InitUsingMultipleAppenders {
   65   
   66       //--------------------------------------------------------------------------
   67       //   Constants:
   68       //--------------------------------------------------------------------------
   69   
   70       //--------------------------------------------------------------------------
   71       //   Protected Variables:
   72       //--------------------------------------------------------------------------
   73   
   74       //--------------------------------------------------------------------------
   75       //   Private Variables:
   76       //--------------------------------------------------------------------------
   77   
   78       private static Logger logger =
   79               Logger.getLogger(InitUsingMultipleAppenders.class);
   80   
   81       //--------------------------------------------------------------------------
   82       //   Constructors:
   83       //--------------------------------------------------------------------------
   84   
   85       //--------------------------------------------------------------------------
   86       //   Public Methods:
   87       //--------------------------------------------------------------------------
   88   
   89       public static void main(String argv[]) {
   90           // Use a PropertyConfigurator to initialize from a property file.
   91           String resource =
   92                   "/examples/lf5/InitUsingMultipleAppenders/example.properties";
   93           URL configFileResource =
   94                   InitUsingMultipleAppenders.class.getResource(resource);
   95           PropertyConfigurator.configure(configFileResource);
   96   
   97           // Add a bunch of logging statements ...
   98           logger.debug("Hello, my name is Homer Simpson.");
   99           logger.debug("Hello, my name is Lisa Simpson.");
  100           logger.debug("Hello, my name is Marge Simpson.");
  101           logger.debug("Hello, my name is Bart Simpson.");
  102           logger.debug("Hello, my name is Maggie Simpson.");
  103   
  104           logger.info("We are the Simpsons!");
  105           logger.info("Mmmmmm .... Chocolate.");
  106           logger.info("Homer likes chocolate");
  107           logger.info("Doh!");
  108           logger.info("We are the Simpsons!");
  109   
  110           logger.warn("Bart: I am through with working! Working is for chumps!" +
  111                   "Homer: Son, I'm proud of you. I was twice your age before " +
  112                   "I figured that out.");
  113           logger.warn("Mmm...forbidden donut.");
  114           logger.warn("D'oh! A deer! A female deer!");
  115           logger.warn("Truly, yours is a butt that won't quit." +
  116                   "- Bart, writing as Woodrow to Ms. Krabappel.");
  117   
  118           logger.error("Dear Baby, Welcome to Dumpsville. Population: you.");
  119           logger.error("Dear Baby, Welcome to Dumpsville. Population: you.",
  120                   new IOException("Dumpsville, USA"));
  121           logger.error("Mr. Hutz, are you aware you're not wearing pants?");
  122           logger.error("Mr. Hutz, are you aware you're not wearing pants?",
  123                   new IllegalStateException("Error !!"));
  124   
  125   
  126           logger.fatal("Eep.");
  127           logger.fatal("Mmm...forbidden donut.",
  128                   new SecurityException("Fatal Exception"));
  129           logger.fatal("D'oh! A deer! A female deer!");
  130           logger.fatal("Mmmmmm .... Chocolate.",
  131                   new SecurityException("Fatal Exception"));
  132       }
  133   
  134       //--------------------------------------------------------------------------
  135       //   Protected Methods:
  136       //--------------------------------------------------------------------------
  137   
  138       //--------------------------------------------------------------------------
  139       //   Private Methods:
  140       //--------------------------------------------------------------------------
  141   
  142       //--------------------------------------------------------------------------
  143       //   Nested Top-Level Classes or Interfaces:
  144       //--------------------------------------------------------------------------
  145   
  146   }

Save This Page
Home » struts-1.3.9-src » examples.lf5 » InitUsingMultipleAppenders » [javadoc | source]