001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/report/CmsLogReport.java,v $
003: * Date : $Date: 2008-02-27 12:05:41 $
004: * Version: $Revision: 1.25 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.report;
033:
034: import org.opencms.main.CmsLog;
035:
036: import java.util.Locale;
037:
038: /**
039: * Report class used for the logfile.<p>
040: *
041: * This prints all messages in the logfile at INFO level.<p>
042: *
043: * @author Alexander Kandzior
044: * @author Jan Baudisch
045: * @author Peter Bonrad
046: *
047: * @version $Revision: 1.25 $
048: *
049: * @since 6.0.0
050: */
051: public class CmsLogReport extends A_CmsReport {
052:
053: /** The buffer to write the log messages to. */
054: private StringBuffer m_buffer;
055:
056: /** The class name to use for the logger. */
057: private Class m_clazz;
058:
059: /**
060: * Constructs a new report using the provided locale for the output language,
061: * using the provided Java class for the log channel.<p>
062: *
063: * @param locale the locale to use for the report output messages
064: * @param clazz the the class for the logger channel
065: */
066: public CmsLogReport(Locale locale, Class clazz) {
067:
068: init(locale, null);
069: m_buffer = new StringBuffer();
070: if (clazz == null) {
071: clazz = CmsLogReport.class;
072: }
073: m_clazz = clazz;
074: }
075:
076: /**
077: * @see org.opencms.report.I_CmsReport#getReportUpdate()
078: */
079: public String getReportUpdate() {
080:
081: return "";
082: }
083:
084: /**
085: * @see org.opencms.report.A_CmsReport#print(java.lang.String, int)
086: */
087: public synchronized void print(String value, int format) {
088:
089: switch (format) {
090: case FORMAT_HEADLINE:
091: m_buffer.append("[ ");
092: m_buffer.append(value);
093: m_buffer.append(" ]");
094: break;
095: case FORMAT_WARNING:
096: m_buffer.append("!!! ");
097: m_buffer.append(value);
098: m_buffer.append(" !!!");
099: 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();
124: }
125:
126: /**
127: * @see org.opencms.report.I_CmsReport#println(java.lang.Throwable)
128: */
129: public synchronized void println(Throwable t) {
130:
131: if (CmsLog.getLog(m_clazz).isInfoEnabled()) {
132: StringBuffer message = new StringBuffer();
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();
140: }
141: }
|