View Javadoc

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 730039 2008-12-30 03:53:19Z byron $
31   * @since 1.5
32   */
33  public class LogChuteSystem implements LogChute
34  {
35  
36      private LogSystem logSystem;
37  
38      /**
39       * Only classes in this package should be creating this.
40       * Users should not have to mess with this class.
41       * @param wrapMe
42       */
43      protected LogChuteSystem(LogSystem wrapMe)
44      {
45          this.logSystem = wrapMe;
46      }
47  
48      /**
49       * @see org.apache.velocity.runtime.log.LogChute#init(org.apache.velocity.runtime.RuntimeServices)
50       */
51      public void init(RuntimeServices rs) throws Exception
52      {
53          logSystem.init(rs);
54      }
55  
56      /**
57       * @see org.apache.velocity.runtime.log.LogChute#log(int, java.lang.String)
58       */
59      public void log(int level, String message)
60      {
61          logSystem.logVelocityMessage(level, message);
62      }
63  
64      /**
65       * First passes off the message at the specified level,
66       * then passes off stack trace of the Throwable as a
67       * 2nd message at the same level.
68       * @param level
69       * @param message
70       * @param t
71       */
72      public void log(int level, String message, Throwable t)
73      {
74          logSystem.logVelocityMessage(level, message);
75          logSystem.logVelocityMessage(level, StringUtils.stackTrace(t));
76      }
77  
78      /**
79       * @see org.apache.velocity.runtime.log.LogChute#isLevelEnabled(int)
80       */
81      public boolean isLevelEnabled(int level)
82      {
83          return true;
84      }
85  
86  }