KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Log4jCategoryExample


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 import org.apache.velocity.app.VelocityEngine;
18 import org.apache.velocity.runtime.RuntimeConstants;
19
20 import org.apache.log4j.Category;
21 import org.apache.log4j.BasicConfigurator;
22
23
24 /**
25  * Simple example class to show how to use an existing Log4j Categeory
26  * as the Velocity logging target.
27  *
28  * @author <a HREF="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
29  * @version $Id: Log4jCategoryExample.java,v 1.1.8.1 2004/03/04 00:18:29 geirm Exp $
30  */

31 public class Log4jCategoryExample
32 {
33     public static String JavaDoc CATEGORY_NAME = "velexample";
34
35     public static void main( String JavaDoc args[] )
36         throws Exception JavaDoc
37     {
38         /*
39          * configure log4j to log to console
40          */

41
42         BasicConfigurator.configure();
43
44         Category log = Category.getInstance( CATEGORY_NAME );
45
46         log.info("Hello from Log4jCategoryExample - ready to start velocity");
47
48         /*
49          * now create a new VelocityEngine instance, and
50          * configure it to use the category
51          */

52
53         VelocityEngine ve = new VelocityEngine();
54
55         ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
56             "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" );
57
58         ve.setProperty("runtime.log.logsystem.log4j.category", CATEGORY_NAME);
59
60         ve.init();
61
62         log.info("this should follow the initialization output from velocity");
63     }
64 }
65
66
Popular Tags