1 package org.apache.velocity.runtime.log;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.velocity.runtime.RuntimeServices;
23 import org.apache.velocity.util.StringUtils;
24
25 /**
26 * Wrapper to make user's custom LogSystem implementations work
27 * with the new LogChute setup.
28 *
29 * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
30 * @version $Id: LogChuteSystem.java 463298 2006-10-12 16:10:32Z henning $
31 */
32 public class LogChuteSystem implements LogChute
33 {
34
35 private LogSystem logSystem;
36
37 /**
38 * Only classes in this package should be creating this.
39 * Users should not have to mess with this class.
40 * @param wrapMe
41 */
42 protected LogChuteSystem(LogSystem wrapMe)
43 {
44 this.logSystem = wrapMe;
45 }
46
47 /**
48 * @see org.apache.velocity.runtime.log.LogChute#init(org.apache.velocity.runtime.RuntimeServices)
49 */
50 public void init(RuntimeServices rs) throws Exception
51 {
52 logSystem.init(rs);
53 }
54
55 /**
56 * @see org.apache.velocity.runtime.log.LogChute#log(int, java.lang.String)
57 */
58 public void log(int level, String message)
59 {
60 logSystem.logVelocityMessage(level, message);
61 }
62
63 /**
64 * First passes off the message at the specified level,
65 * then passes off stack trace of the Throwable as a
66 * 2nd message at the same level.
67 * @param level
68 * @param message
69 * @param t
70 */
71 public void log(int level, String message, Throwable t)
72 {
73 logSystem.logVelocityMessage(level, message);
74 logSystem.logVelocityMessage(level, StringUtils.stackTrace(t));
75 }
76
77 /**
78 * @see org.apache.velocity.runtime.log.LogChute#isLevelEnabled(int)
79 */
80 public boolean isLevelEnabled(int level)
81 {
82 return true;
83 }
84
85 }