KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > Diagnostics


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.subversion;
22
23 import java.io.*;
24
25 import org.netbeans.modules.versioning.util.Utils;
26 import org.openide.ErrorManager;
27
28 /**
29  * Logger shared with svnClientAdapter library.
30  *
31  * @author Petr Kuzel
32  */

33 public final class Diagnostics implements Appendable JavaDoc {
34
35     private static PrintWriter log;
36
37     private static String JavaDoc path;
38
39     public static synchronized void init() {
40         if (log != null) {
41             return;
42         }
43         path = System.getProperty(/*"netbeans.debug."*/"svnLog"); // NOI18N
44
if (path != null && !path.trim().equals("")) {
45             try {
46                 log = new PrintWriter(new OutputStreamWriter(new FileOutputStream(path), "utf8")); // NOI18N
47
System.setProperty("svnClientAdapter.logger.Appendable", "org.netbeans.modules.subversion.Diagnostics"); // NOI18N
48
System.err.println("Subversion diagnostics: ON"); // NOI18N
49
} catch (IOException ex) {
50                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
51             }
52         }
53     }
54
55     public Diagnostics() {
56         init();
57     }
58
59     public synchronized static void println(String JavaDoc msg) {
60         if (log != null) {
61             log.println(Thread.currentThread().getName() + ": " + msg); // NOI18N
62
log.flush();
63         }
64     }
65
66     public synchronized static void printTrace() {
67         if (log != null) {
68             String JavaDoc msg = Utils.getStackTrace();
69             log.println(msg);
70             log.flush();
71         }
72     }
73
74     public synchronized Appendable JavaDoc append(CharSequence JavaDoc csq) throws IOException {
75         try {
76             return log.append(Thread.currentThread().getName() + ": " + csq); // NOI18N
77
} finally {
78             log.flush();
79         }
80     }
81
82     public synchronized Appendable JavaDoc append(CharSequence JavaDoc csq, int start, int end) throws IOException {
83         try {
84             return log.append(csq, start, end);
85         } finally {
86             log.flush();
87         }
88
89     }
90
91     public synchronized Appendable JavaDoc append(char c) throws IOException {
92         try {
93             return log.append(c);
94         } finally {
95             log.flush();
96         }
97     }
98
99     public String JavaDoc toString() {
100         return "" + path; // NOI18N
101
}
102 }
103
Popular Tags