You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2004/11/29 16:34:28 UTC

cvs commit: logging-log4j/tests/src/java/org/apache/log4j SimpleLog.java

ceki        2004/11/29 07:34:27

  Added:       tests/src/java/org/apache/log4j SimpleLog.java
  Log:
  A very simple application. For testing config files manually.
  
  Revision  Changes    Path
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/SimpleLog.java
  
  Index: SimpleLog.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j;
  
  import org.apache.log4j.LogManager;
  import org.apache.log4j.Logger;
  import org.apache.log4j.config.ConfiguratorBase;
  import org.apache.log4j.joran.JoranConfigurator;
  import org.apache.log4j.spi.LoggerRepository;
  
  
  /**
   * Simple application used for manual testing.
   *
   * @author Ceki Gülcü
   */
  public class SimpleLog {
  
    public static void main(String[] args) throws Exception {
      if (args.length != 1) {
        usage("Wrong number of arguments.");
      }
  
      String configFile = args[0];
      LoggerRepository repo = LogManager.getLoggerRepository();
      ConfiguratorBase configurator;
      if (configFile.endsWith(".xml")) {
        JoranConfigurator jc = new JoranConfigurator();
        jc.doConfigure(configFile, repo);
        jc.dumpErrors();
      } else {
        PropertyConfigurator pc = new PropertyConfigurator();
        pc.doConfigure(configFile, repo);
        pc.dumpErrors();
      }
  
      Logger logger = Logger.getLogger(SimpleLog.class);
      int i = 0;
  
      logger.debug("This message number: " + (i++));
      logger.debug("This message number: " + (i++));
      logger.error("This message number: " + (i++), new Exception("Bogus."));
    }
  
    static void usage(String msg) {
      System.err.println(msg);
      System.err.println(
        "Usage: java " + SimpleLog.class.getName() + " configFile\n"
        + "   configFile a log4j configuration file, either in properties "
        + "   or XML format. XML files must have a '.xml' extension.");
      System.exit(1);
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org