01: /**
02: * Copyright (C) 2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.util.monolog.javaLog;
18:
19: import junit.framework.TestCase;
20: import org.objectweb.util.monolog.api.BasicLevel;
21: import org.objectweb.util.monolog.api.Logger;
22: import org.objectweb.util.monolog.api.MonologFactory;
23: import org.objectweb.util.monolog.Monolog;
24:
25: import java.util.Properties;
26:
27: /**
28: *
29: * @author S.Chassande-Barrioz
30: */
31: public class TestConsoleSwitcher extends TestCase {
32:
33: static MonologFactory mf = null;
34:
35: public TestConsoleSwitcher(String s) {
36: super (s);
37: }
38:
39: protected void setUp() throws Exception {
40: if (mf == null) {
41: synchronized (TestCase.class) {
42: if (mf == null) {
43:
44: }
45: }
46: }
47: }
48:
49: public void testSwitch() {
50: testA("switch");
51: }
52:
53: public void testSystemOut() {
54: testA("System.out");
55: }
56:
57: public void testSystemErr() {
58: testA("System.err");
59: }
60:
61: public void testA(String output) {
62: Properties p = new Properties();
63: p
64: .setProperty("monolog.classname",
65: "org.objectweb.util.monolog.wrapper.javaLog.LoggerFactory");
66:
67: p.setProperty("handler.consoleHandler.type", "Console");
68: p.setProperty("handler.consoleHandler.output", output);
69: p.setProperty("handler.consoleHandler.pattern", "%l %d %m%n");
70: p.setProperty("logger.root.level", "INFO");
71: p.setProperty("logger.root.handler.0", "consoleHandler");
72: mf = Monolog.getMonologFactory(p);
73: Logger logger = mf.getLogger("TestConsoleSwitcher.test1");
74: logger.log(BasicLevel.WARN, "warning message via Monolog");
75: logger.log(BasicLevel.INFO, "info message via Monolog");
76: System.out.println("Message on System.out");
77: System.err.println("Message on System.err");
78: }
79: }
|