KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > util > log > PrintWriterTreeLogger


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.dev.util.log;
17
18 import java.io.PrintWriter JavaDoc;
19
20 /**
21  * Tree logger that logs to a print writer.
22  */

23 public final class PrintWriterTreeLogger extends AbstractTreeLogger {
24
25   private final PrintWriter JavaDoc out;
26
27   private final String JavaDoc indent;
28
29   public PrintWriterTreeLogger() {
30     this(new PrintWriter JavaDoc(System.out, true));
31   }
32
33   public PrintWriterTreeLogger(PrintWriter JavaDoc out) {
34     this(out, "");
35   }
36
37   protected PrintWriterTreeLogger(PrintWriter JavaDoc out, String JavaDoc indent) {
38     this.out = out;
39     this.indent = indent;
40   }
41
42   protected AbstractTreeLogger doBranch() {
43     return new PrintWriterTreeLogger(out, indent + " ");
44   }
45
46   protected void doCommitBranch(AbstractTreeLogger childBeingCommitted,
47       Type type, String JavaDoc msg, Throwable JavaDoc caught) {
48     doLog(childBeingCommitted.getBranchedIndex(), type, msg, caught);
49   }
50
51   protected void doLog(int indexOfLogEntryWithinParentLogger, Type type,
52       String JavaDoc msg, Throwable JavaDoc caught) {
53     out.print(indent);
54     if (type.needsAttention()) {
55       out.print("[");
56       out.print(type.getLabel());
57       out.print("] ");
58     }
59
60     out.println(msg);
61     if (caught != null) {
62       caught.printStackTrace(out);
63     }
64   }
65 }
66
Popular Tags