| /* |
| * 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.customLogger; |
| |
| import junit.framework.Test; |
| import junit.framework.TestCase; |
| import junit.framework.TestSuite; |
| |
| import org.apache.log4j.LogManager; |
| import org.apache.log4j.Logger; |
| import org.apache.log4j.joran.JoranConfigurator; |
| import org.apache.log4j.util.*; |
| |
| /** |
| Tests handling of custom loggers. |
| |
| @author Ceki Gülcü |
| */ |
| public class XLoggerTestCase extends TestCase { |
| static String FILTERED = "output/filtered"; |
| static XLogger logger = (XLogger) XLogger.getLogger(XLoggerTestCase.class); |
| |
| public XLoggerTestCase(String name) { |
| super(name); |
| } |
| |
| public void tearDown() { |
| logger.getLoggerRepository().resetConfiguration(); |
| } |
| |
| public void test1() throws Exception { |
| common(1); |
| } |
| |
| public void test2() throws Exception { |
| common(2); |
| } |
| |
| void common(int number) throws Exception { |
| JoranConfigurator jc = new JoranConfigurator(); |
| jc.doConfigure("input/xml/customLogger" + number + ".xml", LogManager.getLoggerRepository()); |
| |
| int i = -1; |
| Logger root = Logger.getRootLogger(); |
| |
| logger.trace("Message " + ++i); |
| logger.debug("Message " + ++i); |
| logger.warn("Message " + ++i); |
| logger.error("Message " + ++i); |
| logger.fatal("Message " + ++i); |
| |
| Exception e = new Exception("Just testing"); |
| logger.debug("Message " + ++i, e); |
| |
| Transformer.transform( |
| "output/temp", FILTERED, |
| new Filter[] { |
| new LineNumberFilter(), new SunReflectFilter(), |
| new JunitTestRunnerFilter() |
| }); |
| assertTrue(Compare.compare(FILTERED, "witness/xml/customLogger." + number)); |
| } |
| |
| public static Test suite() { |
| TestSuite suite = new TestSuite(); |
| suite.addTest(new XLoggerTestCase("test1")); |
| suite.addTest(new XLoggerTestCase("test2")); |
| return suite; |
| } |
| } |