/**
* Copyright (C) 2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.util.monolog.javaLog;
import junit.framework.TestCase;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import org.objectweb.util.monolog.api.MonologFactory;
import org.objectweb.util.monolog.Monolog;
import java.util.Properties;
/**
*
* @author S.Chassande-Barrioz
*/
public class TestConsoleSwitcher extends TestCase {
static MonologFactory mf = null;
public TestConsoleSwitcher(String s) {
super(s);
}
protected void setUp() throws Exception {
if (mf == null) {
synchronized(TestCase.class) {
if (mf == null) {
}
}
}
}
public void testSwitch() {
testA("switch");
}
public void testSystemOut() {
testA("System.out");
}
public void testSystemErr() {
testA("System.err");
}
public void testA(String output) {
Properties p = new Properties();
p.setProperty("monolog.classname", "org.objectweb.util.monolog.wrapper.javaLog.LoggerFactory");
p.setProperty("handler.consoleHandler.type", "Console");
p.setProperty("handler.consoleHandler.output", output);
p.setProperty("handler.consoleHandler.pattern", "%l %d %m%n");
p.setProperty("logger.root.level", "INFO");
p.setProperty("logger.root.handler.0", "consoleHandler");
mf = Monolog.getMonologFactory(p);
Logger logger = mf.getLogger("TestConsoleSwitcher.test1");
logger.log(BasicLevel.WARN, "warning message via Monolog");
logger.log(BasicLevel.INFO, "info message via Monolog");
System.out.println("Message on System.out");
System.err.println("Message on System.err");
}
}