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;
18:
19: import org.objectweb.util.monolog.api.MonologFactory;
20: import org.objectweb.util.monolog.api.TopicalLogger;
21: import org.objectweb.util.monolog.api.Handler;
22: import org.objectweb.util.monolog.api.BasicLevel;
23: import junit.framework.TestCase;
24:
25: /**
26: *
27: * @author S.Chassande-Barrioz
28: */
29: public class TestHandlerLevel extends TestCase {
30:
31: public TestHandlerLevel(String s) {
32: super (s);
33: }
34:
35: public void testProgConfig() throws Exception {
36: String className = System.getProperty(
37: Monolog.MONOLOG_CLASS_NAME,
38: Monolog.JDK_WRAPPER_CLASS_NAME);
39: Monolog.monologFactory = Monolog.getDefaultMonologFactory();
40: MonologFactory mf = Monolog
41: .instanciateMonologFactory(className);
42: TopicalLogger l = (TopicalLogger) mf
43: .getLogger("org.objectweb.util.monolog.TestHandlerLevel.testA");
44: l.setIntLevel(BasicLevel.DEBUG);
45: l.setAdditivity(false);
46:
47: Handler h1 = mf.createHandler("h1", "console");
48: h1.setAttribute(Handler.OUTPUT_ATTRIBUTE, "System.out");
49: h1.setAttribute(Handler.LEVEL_ATTRIBUTE, "WARN");
50: h1.setAttribute(Handler.PATTERN_ATTRIBUTE, "first handler: %m");
51: h1.setAttribute("activation", mf);
52: l.addHandler(h1);
53:
54: Handler h2 = mf.createHandler("h2", "console");
55: h2.setAttribute(Handler.OUTPUT_ATTRIBUTE, "System.out");
56: h2
57: .setAttribute(Handler.PATTERN_ATTRIBUTE,
58: "second handler: %m");
59: h2.setAttribute("activation", mf);
60: l.addHandler(h2);
61: l = (TopicalLogger) mf
62: .getLogger("org.objectweb.util.monolog.TestHandlerLevel.testA.l1");
63: l.log(BasicLevel.DEBUG, "(" + className
64: + ") this message must be printed only one time");
65: }
66: }
|