001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.util;
017:
018: import org.apache.log4j.*;
019:
020: import java.io.PrintWriter;
021:
022: /**
023: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
024: */
025: public class Log4jPrintWriter extends PrintWriter {
026: private final StringBuffer text = new StringBuffer("");
027: private final org.apache.log4j.Logger logger;
028: private final Priority priority;
029:
030: public Log4jPrintWriter(String category, Priority priority) {
031: super (System.err);
032: logger = org.apache.log4j.Logger.getLogger(category);
033: this .priority = priority;
034: }
035:
036: public void close() {
037: flush();
038: }
039:
040: private void flushLine() {
041: logger.log(priority, text.toString());
042: text.setLength(0);
043: }
044:
045: public void flush() {
046: if (!text.toString().equals("")) {
047: flushLine();
048: }
049: }
050:
051: public void print(boolean b) {
052: text.append(b);
053: }
054:
055: public void print(char c) {
056: text.append(c);
057: }
058:
059: public void print(char[] s) {
060: text.append(s);
061: }
062:
063: public void print(double d) {
064: text.append(d);
065: }
066:
067: public void print(float f) {
068: text.append(f);
069: }
070:
071: public void print(int i) {
072: text.append(i);
073: }
074:
075: public void print(long l) {
076: text.append(l);
077: }
078:
079: public void print(Object obj) {
080: text.append(obj);
081: }
082:
083: public void print(String s) {
084: text.append(s);
085: }
086:
087: public void println() {
088: if (!text.toString().equals("")) {
089: flushLine();
090: }
091: }
092:
093: public void println(boolean x) {
094: text.append(x);
095: flushLine();
096: }
097:
098: public void println(char x) {
099: text.append(x);
100: flushLine();
101: }
102:
103: public void println(char[] x) {
104: text.append(x);
105: flushLine();
106: }
107:
108: public void println(double x) {
109: text.append(x);
110: flushLine();
111: }
112:
113: public void println(float x) {
114: text.append(x);
115: flushLine();
116: }
117:
118: public void println(int x) {
119: text.append(x);
120: flushLine();
121: }
122:
123: public void println(long x) {
124: text.append(x);
125: flushLine();
126: }
127:
128: public void println(Object x) {
129: text.append(x);
130: flushLine();
131: }
132:
133: public void println(String x) {
134: text.append(x);
135: flushLine();
136: }
137: }
|