KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jmxdebug > web > velocity > ServletLogger


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

17
18 package org.apache.geronimo.jmxdebug.web.velocity;
19
20 import org.apache.velocity.runtime.log.LogSystem;
21 import org.apache.velocity.runtime.RuntimeServices;
22 import org.apache.velocity.runtime.RuntimeConstants;
23
24 import javax.servlet.ServletContext JavaDoc;
25
26 /**
27  * Simple wrapper for the servlet log.
28  *
29  * @version $Rev: 45929 $ $Date: 2004-09-11 17:10:38 -0700 (Sat, 11 Sep 2004) $
30  */

31 public class ServletLogger {
32     private ServletContext JavaDoc servletContext = null;
33
34     private static final String JavaDoc PREFIX = " Velocity ";
35
36     public ServletLogger(ServletContext JavaDoc sc) {
37         servletContext = sc;
38     }
39
40     /**
41      * init()
42      */

43     public void init(RuntimeServices rs)
44             throws Exception JavaDoc {
45     }
46
47     /**
48      * Send a log message from Velocity.
49      */

50     public void logVelocityMessage(int level, String JavaDoc message) {
51         
52         switch (level) {
53             case LogSystem.WARN_ID:
54                 servletContext.log(PREFIX + RuntimeConstants.WARN_PREFIX + message);
55                 break;
56             case LogSystem.INFO_ID:
57                 servletContext.log(PREFIX + RuntimeConstants.INFO_PREFIX + message);
58                 break;
59             case LogSystem.DEBUG_ID:
60                 servletContext.log(PREFIX + RuntimeConstants.DEBUG_PREFIX + message);
61                 break;
62             case LogSystem.ERROR_ID:
63                 servletContext.log(PREFIX + RuntimeConstants.ERROR_PREFIX + message);
64                 break;
65             default:
66                 servletContext.log(PREFIX + " : " + message);
67                 break;
68         }
69     }
70 }
71
Popular Tags