KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > TestHandlerLevel


1 /**
2  * Copyright (C) 2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18 package org.objectweb.util.monolog;
19
20 import org.objectweb.util.monolog.api.MonologFactory;
21 import org.objectweb.util.monolog.api.TopicalLogger;
22 import org.objectweb.util.monolog.api.Handler;
23 import org.objectweb.util.monolog.api.BasicLevel;
24 import junit.framework.TestCase;
25
26 /**
27  *
28  * @author S.Chassande-Barrioz
29  */

30 public class TestHandlerLevel extends TestCase {
31
32     public TestHandlerLevel(String JavaDoc s) {
33         super(s);
34     }
35
36     public void testProgConfig() throws Exception JavaDoc {
37         String JavaDoc className = System.getProperty(Monolog.MONOLOG_CLASS_NAME, Monolog.JDK_WRAPPER_CLASS_NAME);
38         Monolog.monologFactory = Monolog.getDefaultMonologFactory();
39         MonologFactory mf = Monolog.instanciateMonologFactory(className);
40         TopicalLogger l = (TopicalLogger) mf.getLogger(
41             "org.objectweb.util.monolog.TestHandlerLevel.testA");
42         l.setIntLevel(BasicLevel.DEBUG);
43         l.setAdditivity(false);
44
45         Handler h1 = mf.createHandler("h1", "console");
46         h1.setAttribute(Handler.OUTPUT_ATTRIBUTE, "System.out");
47         h1.setAttribute(Handler.LEVEL_ATTRIBUTE, "WARN");
48         h1.setAttribute(Handler.PATTERN_ATTRIBUTE, "first handler: %m");
49         h1.setAttribute("activation",mf);
50         l.addHandler(h1);
51
52         Handler h2 = mf.createHandler("h2", "console");
53         h2.setAttribute(Handler.OUTPUT_ATTRIBUTE, "System.out");
54         h2.setAttribute(Handler.PATTERN_ATTRIBUTE, "second handler: %m");
55         h2.setAttribute("activation",mf);
56         l.addHandler(h2);
57         l = (TopicalLogger) mf.getLogger(
58             "org.objectweb.util.monolog.TestHandlerLevel.testA.l1");
59         l.log(BasicLevel.DEBUG, "(" + className + ") this message must be printed only one time");
60     }
61 }
62
Popular Tags