1 package org.apache.velocity.site.doxia.velocity;
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.runtime.log.LogChute;
24 import org.codehaus.plexus.logging.LogEnabled;
25 import org.codehaus.plexus.logging.Logger;
26
27 /**
28 * An implementation of a {@link LogChute} to use with Velocity that logs into
29 * Plexus logging.
30 *
31 * @plexus.component role="org.apache.velocity.site.doxia.velocity.PlexusLogger"
32 *
33 * @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
34 * @version $Revision: 526751 $
35 */
36 public class PlexusLogger implements LogChute, LogEnabled
37 {
38 public static final String ROLE = PlexusLogger.class.getName();
39
40 /** Plexus Logger Object */
41 private Logger logger = null;
42
43 /**
44 * Creates a new PlexusLogger object.
45 */
46 public PlexusLogger()
47 {
48 }
49
50 public void enableLogging(final Logger logger)
51 {
52 this.logger = logger;
53 }
54
55 /**
56 * @see LogChute#init(RuntimeServices)
57 */
58 public void init(final RuntimeServices rsvc) throws Exception
59 {
60 }
61
62 /**
63 * @see LogChute#isLevelEnabled(int)
64 */
65 public boolean isLevelEnabled(final int logLevel)
66 {
67 switch (logLevel)
68 {
69 case LogChute.DEBUG_ID:
70 case LogChute.TRACE_ID:
71 {
72 return logger.isDebugEnabled();
73 }
74
75 case LogChute.ERROR_ID:
76 {
77 return logger.isErrorEnabled();
78 }
79
80 case LogChute.INFO_ID:
81 {
82 return logger.isInfoEnabled();
83 }
84
85 case LogChute.WARN_ID:
86 {
87 return logger.isWarnEnabled();
88 }
89
90 default:
91 {
92 return false;
93 }
94 }
95 }
96
97 /**
98 * @see LogChute#log(int, String)
99 */
100 public void log(final int logLevel, final String msg)
101 {
102 switch (logLevel)
103 {
104 case LogChute.DEBUG_ID:
105 case LogChute.TRACE_ID:
106 {
107 logger.debug(msg);
108 break;
109 }
110
111 case LogChute.ERROR_ID:
112 {
113 logger.error(msg);
114 break;
115 }
116
117 case LogChute.INFO_ID:
118 {
119 logger.info(msg);
120 break;
121 }
122
123 case LogChute.WARN_ID:
124 {
125 logger.warn(msg);
126 break;
127 }
128
129 default:
130 {
131 break; // do nothing
132 }
133 }
134 }
135
136 /**
137 * @see LogChute#log(int, String, Throwable)
138 */
139 public void log(final int logLevel, final String msg, final Throwable t)
140 {
141 switch (logLevel)
142 {
143 case LogChute.DEBUG_ID:
144 case LogChute.TRACE_ID:
145 {
146 logger.debug(msg, t);
147 break;
148 }
149
150 case LogChute.ERROR_ID:
151 {
152 logger.error(msg, t);
153 break;
154 }
155
156 case LogChute.INFO_ID:
157 {
158 logger.info(msg, t);
159 break;
160 }
161
162 case LogChute.WARN_ID:
163 {
164 logger.warn(msg, t);
165 break;
166 }
167
168 default:
169 {
170 break; // do nothing
171 }
172 }
173 }
174 }