001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * SystemOutLogTarget.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.util;
030:
031: import java.io.IOException;
032: import java.io.ObjectInputStream;
033: import java.io.PrintStream;
034: import java.io.Serializable;
035:
036: import org.jfree.util.LogTarget;
037:
038: /**
039: * A log target that sends all log messages to the <code>System.out</code> stream.
040: *
041: * @author Thomas Morgner
042: * @deprecated This class is no longer used. This class will be removed in the next version.
043: */
044: public class SystemOutLogTarget implements LogTarget, Serializable {
045: /**
046: * The printstream we use ..
047: */
048: private transient PrintStream printStream;
049:
050: /**
051: * The default constructor. Initializes this target with the system.out stream.
052: * <p/>
053: * All {@link org.jfree.util.LogTarget} implementations need a default constructor.
054: */
055: public SystemOutLogTarget() {
056: this (System.out);
057: }
058:
059: /**
060: * The default constructor. Initializes this target with the given stream.
061: * <p/>
062: *
063: * @param printStream the print stream that is used to write the content.
064: */
065: public SystemOutLogTarget(final PrintStream printStream) {
066: if (printStream == null) {
067: throw new NullPointerException();
068: }
069: this .printStream = printStream;
070: }
071:
072: /**
073: * Logs a message to the main log stream. All attached logStreams will also receive this
074: * message. If the given log-level is higher than the given debug-level in the main
075: * config file, no logging will be done.
076: *
077: * @param level log level of the message.
078: * @param message text to be logged.
079: */
080: public void log(int level, final Object message) {
081: if (level > 3) {
082: level = 3;
083: }
084: printStream.print(LEVELS[level]);
085: printStream.println(message);
086: if (level < 3) {
087: printStream.flush();
088: }
089: }
090:
091: /**
092: * logs an message to the main-log stream. All attached logStreams will also receive
093: * this message. If the given log-level is higher than the given debug-level in the main
094: * config file, no logging will be done.
095: * <p/>
096: * The exception's stacktrace will be appended to the log-stream
097: *
098: * @param level log level of the message.
099: * @param message text to be logged.
100: * @param e the exception, which should be logged.
101: */
102: public void log(int level, final Object message, final Exception e) {
103: if (level > 3) {
104: level = 3;
105: }
106: printStream.print(LEVELS[level]);
107: printStream.println(message);
108: e.printStackTrace(printStream);
109: if (level < 3) {
110: printStream.flush();
111: }
112: }
113:
114: /**
115: * Handler for serialization.
116: *
117: * @param in the object input stream
118: * @throws IOException if an IO-Error occured
119: * @throws ClassNotFoundException if a required class could not be located.
120: */
121: private void readObject(final ObjectInputStream in)
122: throws IOException, ClassNotFoundException {
123: printStream = System.out;
124: }
125: }
|