KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > localhistory > 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.localhistory;
22
23 import java.io.*;
24 import java.text.SimpleDateFormat JavaDoc;
25 import java.util.Date JavaDoc;
26 import org.openide.ErrorManager;
27
28 /**
29  *
30  * @author Petr Kuzel
31  */

32 public final class Diagnostics {
33
34     private static PrintWriter log;
35
36     private static String JavaDoc path;
37
38     public static final boolean ON;
39     
40     private static final SimpleDateFormat JavaDoc defaultFormat = new SimpleDateFormat JavaDoc("dd-MM-yyyy:HH-mm-ss.S"); //DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
41

42     static {
43 // if (log != null) {
44
// return;
45
// }
46
path = System.getProperty("netbeans.debug.localHistoryLog"); // NOI18N
47
if (path != null && !path.trim().equals("")) {
48             try {
49                 log = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(path, true)), "utf8")); // NOI18N
50
System.err.println("LocalHistory diagnostics: ON"); // NOI18N
51
} catch (IOException ex) {
52                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
53                 log = null;
54             }
55         }
56         ON = log != null;
57     }
58
59     public Diagnostics() {
60         //init();
61
}
62
63     public synchronized static void println(String JavaDoc msg) {
64         if (log != null) {
65             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
66             sb.append(defaultFormat.format(new Date JavaDoc(System.currentTimeMillis())));
67             sb.append(":");
68             sb.append(msg);
69             sb.append('\t');
70             sb.append(Thread.currentThread().getName());
71             log.println(sb.toString()); // NOI18N
72
log.flush();
73         }
74     }
75     
76     public synchronized static void logCreate(File file, File storeFile, long ts, String JavaDoc from, String JavaDoc to) {
77         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
78         sb.append("create");
79         sb.append('\t');
80         sb.append(file.getAbsolutePath());
81         sb.append('\t');
82         sb.append(storeFile.getAbsolutePath());
83         sb.append('\t');
84         sb.append(ts);
85         sb.append('\t');
86         sb.append(from);
87         sb.append('\t');
88         sb.append(to);
89         println(sb.toString());
90     }
91
92     public synchronized static void logChange(File file, File storeFile, long ts) {
93         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
94         sb.append("change");
95         sb.append('\t');
96         sb.append(file.getAbsolutePath());
97         sb.append('\t');
98         sb.append(storeFile.getAbsolutePath());
99         sb.append('\t');
100         sb.append(ts);
101         
102         println(sb.toString());
103     }
104     
105     
106     public synchronized static void logDelete(File file, File storeFile, long ts) {
107         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
108         sb.append("delete");
109         sb.append('\t');
110         sb.append(file.getAbsolutePath());
111         sb.append('\t');
112         sb.append(storeFile.getAbsolutePath());
113         sb.append('\t');
114         sb.append(ts);
115         println(sb.toString());
116     }
117
118     public String JavaDoc toString() {
119         return "" + path; // NOI18N
120
}
121 }
122
Popular Tags