KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > logging > AntProjectLogger


1 /*
2  * Copyright 2003, 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 package org.apache.ws.jaxme.logging;
18
19 import java.io.PrintWriter JavaDoc;
20 import java.io.StringWriter JavaDoc;
21
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.Task;
24
25 /** A wrapper for the Ant logger.
26  */

27 public class AntProjectLogger implements Logger {
28     private final String JavaDoc cName;
29     private final Task task;
30     
31     /** Creates a new instance for the given task.
32      */

33     public AntProjectLogger(String JavaDoc pName, Task pTask) {
34         cName = pName;
35         task = pTask;
36     }
37     
38     public boolean isFinestEnabled() { return true; }
39     public boolean isFinerEnabled() { return true; }
40     public boolean isFineEnabled() { return true; }
41     public boolean isInfoEnabled() { return true; }
42     public boolean isWarnEnabled() { return true; }
43     public boolean isErrorEnabled() { return true; }
44     
45     protected String JavaDoc asString(Object JavaDoc[] pDetails) {
46         if (pDetails == null) {
47             return "";
48         }
49         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
50         for (int i = 0; i < pDetails.length; i++) {
51             if (i > 0) {
52                 sb.append(", ");
53             }
54             sb.append(pDetails[i]);
55         }
56         return sb.toString();
57     }
58     
59     protected void log(int pLevel, String JavaDoc mName, String JavaDoc pMsg) {
60         task.log(cName + "." + mName + ": " + pMsg, pLevel);
61     }
62     
63     public void entering(String JavaDoc mName, Object JavaDoc[] pDetails) {
64         log(Project.MSG_VERBOSE, mName, "-> " + asString(pDetails));
65     }
66     
67     public void entering(String JavaDoc mName) {
68         log(Project.MSG_VERBOSE, mName, "->");
69     }
70     
71     public void entering(String JavaDoc mName, Object JavaDoc pDetails) {
72         log(Project.MSG_VERBOSE, mName, "-> " + pDetails);
73     }
74     
75     public void exiting(String JavaDoc mName, Object JavaDoc[] pDetails) {
76         log(Project.MSG_VERBOSE, mName, "<- " + asString(pDetails));
77     }
78     
79     public void exiting(String JavaDoc mName) {
80         log(Project.MSG_VERBOSE, mName, "<-");
81     }
82     
83     public void exiting(String JavaDoc mName, Object JavaDoc pDetails) {
84         log(Project.MSG_VERBOSE, mName, "<- " + pDetails);
85     }
86     
87     public void throwing(String JavaDoc mName, Throwable JavaDoc pThrowable) {
88         StringWriter JavaDoc sw = new StringWriter JavaDoc();
89         pThrowable.printStackTrace(new PrintWriter JavaDoc(sw));
90         error(mName, sw.toString());
91     }
92     
93     public void finest(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
94         finest(mName, pMsg + ", " + asString(pDetails));
95     }
96     
97     public void finest(String JavaDoc mName, String JavaDoc pMsg) {
98         log(Project.MSG_DEBUG, mName, pMsg);
99     }
100     
101     public void finest(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
102         finest(mName, pMsg + ", " + pDetails);
103     }
104     
105     public void finer(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
106         finer(mName, pMsg + ", " + asString(pDetails));
107     }
108     
109     public void finer(String JavaDoc mName, String JavaDoc pMsg) {
110         log(Project.MSG_DEBUG, mName, pMsg);
111     }
112     
113     public void finer(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
114         finer(mName, pMsg + ", " + pDetails);
115     }
116     
117     public void fine(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
118         fine(mName, pMsg + ", " + asString(pDetails));
119     }
120     
121     public void fine(String JavaDoc mName, String JavaDoc pMsg) {
122         log(Project.MSG_VERBOSE, mName, pMsg);
123     }
124     
125     public void fine(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
126         fine(mName, pMsg + ", " + pDetails);
127     }
128     
129     public void info(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
130         info(mName, pMsg + ", " + asString(pDetails));
131     }
132     
133     public void info(String JavaDoc mName, String JavaDoc pMsg) {
134         log(Project.MSG_INFO, mName, pMsg);
135     }
136     
137     public void info(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
138         info(mName, pMsg + ", " + pDetails);
139     }
140     
141     public void warn(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
142         warn(mName, pMsg + ", " + asString(pDetails));
143     }
144     
145     public void warn(String JavaDoc mName, String JavaDoc pMsg) {
146         log(Project.MSG_WARN, mName, pMsg);
147     }
148     
149     public void warn(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
150         warn(mName, pMsg + ", " + pDetails);
151     }
152     
153     public void error(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc[] pDetails) {
154         error(mName, pMsg + ", " + asString(pDetails));
155     }
156     
157     public void error(String JavaDoc mName, String JavaDoc pMsg) {
158         log(Project.MSG_ERR, mName, pMsg);
159     }
160     
161     public void error(String JavaDoc mName, String JavaDoc pMsg, Object JavaDoc pDetails) {
162         error(mName, pMsg + ", " + pDetails);
163     }
164 }
165
Popular Tags