KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > report > CmsLogReport


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/report/CmsLogReport.java,v $
3  * Date : $Date: 2006/10/04 07:35:21 $
4  * Version: $Revision: 1.22 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.report;
33
34 import org.opencms.main.CmsLog;
35
36 import java.util.Locale JavaDoc;
37
38 /**
39  * Report class used for the logfile.<p>
40  *
41  * This prints all messages in the logfile at INFO level.<p>
42  *
43  * @author Alexander Kandzior
44  * @author Jan Baudisch
45  * @author Peter Bonrad
46  *
47  * @version $Revision: 1.22 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsLogReport extends A_CmsReport {
52
53     /** The buffer to write the log messages to. */
54     private StringBuffer JavaDoc m_buffer;
55
56     /** The class name to use for the logger. */
57     private Class JavaDoc m_clazz;
58
59     /**
60      * Constructs a new report using the provided locale for the output language,
61      * using the provided Java class for the log channel.<p>
62      *
63      * @param locale the locale to use for the report output messages
64      * @param clazz the the class for the logger channel
65      */

66     public CmsLogReport(Locale JavaDoc locale, Class JavaDoc clazz) {
67
68         init(locale, null);
69         m_buffer = new StringBuffer JavaDoc();
70         if (clazz == null) {
71             clazz = CmsLogReport.class;
72         }
73         m_clazz = clazz;
74     }
75
76     /**
77      * @see org.opencms.report.I_CmsReport#getReportUpdate()
78      */

79     public String JavaDoc getReportUpdate() {
80
81         return "";
82     }
83
84     /**
85      * @see org.opencms.report.A_CmsReport#print(java.lang.String, int)
86      */

87     public synchronized void print(String JavaDoc value, int format) {
88
89         switch (format) {
90             case FORMAT_HEADLINE:
91                 m_buffer.append("[ ");
92                 m_buffer.append(value);
93                 m_buffer.append(" ]");
94                 break;
95             case FORMAT_WARNING:
96                 m_buffer.append("!!! ");
97                 m_buffer.append(value);
98                 m_buffer.append(" !!!");
99                 addWarning(value);
100                 break;
101             case FORMAT_ERROR:
102                 m_buffer.append("!!! ");
103                 m_buffer.append(value);
104                 m_buffer.append(" !!!");
105                 addError(value);
106                 break;
107             case FORMAT_NOTE:
108             case FORMAT_OK:
109             case FORMAT_DEFAULT:
110             default:
111                 m_buffer.append(value);
112         }
113     }
114
115     /**
116      * @see org.opencms.report.I_CmsReport#println()
117      */

118     public synchronized void println() {
119
120         if (CmsLog.getLog(m_clazz).isInfoEnabled()) {
121             CmsLog.getLog(m_clazz).info(m_buffer.toString());
122         }
123         m_buffer = new StringBuffer JavaDoc();
124     }
125
126     /**
127      * @see org.opencms.report.I_CmsReport#println(java.lang.Throwable)
128      */

129     public synchronized void println(Throwable JavaDoc t) {
130
131         if (CmsLog.getLog(m_clazz).isInfoEnabled()) {
132             StringBuffer JavaDoc message = new StringBuffer JavaDoc();
133             message.append(getMessages().key(Messages.RPT_EXCEPTION_0));
134             message.append(t.getMessage());
135             m_buffer.append(message);
136             addError(message.toString());
137             CmsLog.getLog(m_clazz).info(m_buffer.toString(), t);
138         }
139         m_buffer = new StringBuffer JavaDoc();
140     }
141 }
Popular Tags