KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > startup > TopLogging


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 package org.netbeans.core.startup;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.ByteArrayOutputStream JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.FileOutputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.PrintStream JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29 import java.io.StringWriter JavaDoc;
30 import java.io.UnsupportedEncodingException JavaDoc;
31 import java.text.DateFormat JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.Date JavaDoc;
34 import java.util.HashSet JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.Locale JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.MissingResourceException JavaDoc;
39 import java.util.Set JavaDoc;
40 import java.util.StringTokenizer JavaDoc;
41 import java.util.concurrent.Callable JavaDoc;
42 import java.util.logging.Formatter JavaDoc;
43 import java.util.logging.Handler JavaDoc;
44 import java.util.logging.Level JavaDoc;
45 import java.util.logging.LogManager JavaDoc;
46 import java.util.logging.LogRecord JavaDoc;
47 import java.util.logging.Logger JavaDoc;
48 import java.util.logging.StreamHandler JavaDoc;
49 import org.openide.filesystems.FileUtil;
50 import org.openide.util.Lookup;
51 import org.openide.util.LookupEvent;
52 import org.openide.util.LookupListener;
53 import org.openide.util.NbBundle;
54 import org.openide.util.RequestProcessor;
55 import org.xml.sax.SAXParseException JavaDoc;
56
57 /**
58  * Class that sets the java.util.logging.LogManager configuration to log into
59  * the right file and put there the right content. Does nothing if
60  * either <code>java.util.logging.config.file</code> or
61  * <code>java.util.logging.config.class</code> is specified.
62  */

63 public final class TopLogging {
64     private static boolean disabledConsole = ! Boolean.getBoolean("netbeans.logger.console"); // NOI18N
65
/** reference to the old error stream */
66     private static final PrintStream JavaDoc OLD_ERR = System.err;
67     static {
68         System.setProperty("sun.awt.exception.handler", "org.netbeans.core.startup.TopLogging$AWTHandler"); // NOI18N
69
}
70
71     /** Initializes the logging configuration. Invoked by <code>LogManager.readConfiguration</code> method.
72      */

73     public TopLogging() {
74         ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc();
75         PrintStream JavaDoc ps = new PrintStream JavaDoc(os);
76
77         Iterator JavaDoc it = System.getProperties().entrySet().iterator();
78         while (it.hasNext()) {
79             Map.Entry JavaDoc e = (Map.Entry JavaDoc)it.next();
80
81             String JavaDoc key = (String JavaDoc)e.getKey();
82
83             if ("sun.os.patch.level".equals(key)) { // NOI18N
84
// skip this property as it does not mean level of logging
85
continue;
86             }
87
88             String JavaDoc v = (String JavaDoc)e.getValue();
89
90             if (key.endsWith(".level")) {
91                 ps.print(key);
92                 ps.print("=");
93                 ps.println(v);
94             }
95         }
96         ps.close();
97         try {
98             LogManager.getLogManager().readConfiguration(new ByteArrayInputStream JavaDoc(os.toByteArray()));
99         } catch (IOException JavaDoc ex) {
100             ex.printStackTrace();
101         }
102
103
104         Logger JavaDoc logger = Logger.getLogger (""); // NOI18N
105

106         Handler JavaDoc[] old = logger.getHandlers();
107         for (int i = 0; i < old.length; i++) {
108             logger.removeHandler(old[i]);
109         }
110         logger.addHandler(defaultHandler ());
111         if (!disabledConsole) { // NOI18N
112
logger.addHandler (streamHandler ());
113         }
114         logger.addHandler(new LookupDel());
115
116         /* TBD:
117         for (Handler h : Lookup.getDefault().lookupAll(Handler.class)) {
118             logger.addHandler(h);
119         }
120          */

121     }
122
123     private static String JavaDoc previousUser;
124     static final void initialize() {
125         if (previousUser == null || previousUser.equals(System.getProperty("netbeans.user"))) {
126             // useful from tests
127
streamHandler = null;
128             defaultHandler = null;
129         }
130
131         if (System.getProperty("java.util.logging.config.file") != null) { // NOI18N
132
return;
133         }
134         String JavaDoc v = System.getProperty("java.util.logging.config.class"); // NOI18N
135
String JavaDoc p = TopLogging.class.getName();
136         if (v != null && !v.equals(p)) {
137             return;
138         }
139
140         // initializes the properties
141
new TopLogging();
142         // next time invoke the constructor of TopLogging itself please
143
System.setProperty("java.util.logging.config.class", p);
144
145         ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc();
146         PrintStream JavaDoc ps = new PrintStream JavaDoc(os);
147         printSystemInfo(ps);
148         ps.close();
149         try {
150             Logger JavaDoc logger = Logger.getLogger (TopLogging.class.getName()); // NOI18N
151
logger.log(Level.INFO, os.toString("utf-8"));
152         } catch (UnsupportedEncodingException JavaDoc ex) {
153             assert false;
154         }
155
156         if (!(System.err instanceof LgStream)) {
157             System.setErr(new LgStream(Logger.getLogger("stderr"))); // NOI18N
158
}
159     }
160     
161
162     private static void printSystemInfo(PrintStream JavaDoc ps) {
163         DateFormat JavaDoc df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
164         Date JavaDoc date = new Date JavaDoc();
165
166         ps.println("-------------------------------------------------------------------------------"); // NOI18N
167
ps.println(">Log Session: "+df.format (date)); // NOI18N
168
ps.println(">System Info: "); // NOI18N
169

170         String JavaDoc buildNumber = System.getProperty ("netbeans.buildnumber"); // NOI18N
171
String JavaDoc currentVersion = NbBundle.getMessage(TopLogging.class, "currentVersion", buildNumber );
172         ps.println(" Product Version = " + currentVersion); // NOI18N
173
ps.println(" Operating System = " + System.getProperty("os.name", "unknown")
174                    + " version " + System.getProperty("os.version", "unknown")
175                    + " running on " + System.getProperty("os.arch", "unknown"));
176         ps.println(" Java; VM; Vendor; Home = " + System.getProperty("java.version", "unknown") + "; " +
177                    System.getProperty("java.vm.name", "unknown") + " " + System.getProperty("java.vm.version", "") + "; " +
178                    System.getProperty("java.vendor", "unknown") + "; " +
179                    System.getProperty("java.home", "unknown"));
180         ps.print( " System Locale; Encoding = " + Locale.getDefault()); // NOI18N
181
String JavaDoc branding = NbBundle.getBranding ();
182         if (branding != null) {
183             ps.print(" (" + branding + ")"); // NOI18N
184
}
185         ps.println("; " + System.getProperty("file.encoding", "unknown")); // NOI18N
186
ps.println(" Home Dir.; Current Dir. = " + System.getProperty("user.home", "unknown") + "; " +
187                    System.getProperty("user.dir", "unknown"));
188         ps.print( " Installation; User Dir. = "); // NOI18N
189
String JavaDoc nbdirs = System.getProperty("netbeans.dirs");
190         if (nbdirs != null) { // noted in #67862: should show all clusters here.
191
StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(nbdirs, File.pathSeparator);
192             while (tok.hasMoreTokens()) {
193                 ps.print(FileUtil.normalizeFile(new File JavaDoc(tok.nextToken())));
194                 ps.print(File.pathSeparatorChar);
195             }
196         }
197         ps.println(CLIOptions.getHomeDir() + "; " + CLIOptions.getUserDir()); // NOI18N
198
ps.println(" Boot & Ext. Classpath = " + createBootClassPath()); // NOI18N
199
ps.println(" Application Classpath = " + System.getProperty("java.class.path", "unknown")); // NOI18N
200
ps.println(" Startup Classpath = " + System.getProperty("netbeans.dynamic.classpath", "unknown")); // NOI18N
201
ps.println("-------------------------------------------------------------------------------"); // NOI18N
202
}
203
204     // Copied from NbClassPath:
205
private static String JavaDoc createBootClassPath() {
206         // boot
207
String JavaDoc boot = System.getProperty("sun.boot.class.path"); // NOI18N
208
StringBuffer JavaDoc sb = (boot != null ? new StringBuffer JavaDoc(boot) : new StringBuffer JavaDoc());
209         
210         // std extensions
211
findBootJars(System.getProperty("java.ext.dirs"), sb);
212         findBootJars(System.getProperty("java.endorsed.dirs"), sb);
213         return sb.toString();
214     }
215
216     /** Scans path list for something that can be added to classpath.
217      * @param extensions null or path list
218      * @param sb buffer to put results to
219      */

220     private static void findBootJars(final String JavaDoc extensions, final StringBuffer JavaDoc sb) {
221         if (extensions != null) {
222             for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(extensions, File.pathSeparator); st.hasMoreTokens();) {
223                 File JavaDoc dir = new File JavaDoc(st.nextToken());
224                 File JavaDoc[] entries = dir.listFiles();
225                 if (entries != null) {
226                     for (int i = 0; i < entries.length; i++) {
227                         String JavaDoc name = entries[i].getName().toLowerCase(Locale.US);
228                         if (name.endsWith(".zip") || name.endsWith(".jar")) { // NOI18N
229
if (sb.length() > 0) {
230                                 sb.append(File.pathSeparatorChar);
231                             }
232                             sb.append(entries[i].getPath());
233                         }
234                     }
235                 }
236             }
237         }
238     }
239
240     /** Logger for test purposes.
241      */

242     static Handler JavaDoc createStreamHandler (PrintStream JavaDoc pw) {
243         StreamHandler JavaDoc s = new StreamHandler JavaDoc (
244             pw, NbFormatter.FORMATTER
245         );
246         return s;
247     }
248     
249     private static java.util.logging.Handler JavaDoc streamHandler;
250     private static synchronized java.util.logging.Handler JavaDoc streamHandler () {
251         if (streamHandler == null) {
252             StreamHandler JavaDoc sth = new StreamHandler JavaDoc (OLD_ERR, NbFormatter.FORMATTER);
253             sth.setLevel(Level.ALL);
254             streamHandler = new NonClose(sth, 500);
255         }
256         return streamHandler;
257     }
258     
259     private static java.util.logging.Handler JavaDoc defaultHandler;
260     private static synchronized java.util.logging.Handler JavaDoc defaultHandler () {
261         if (defaultHandler != null) return defaultHandler;
262
263         String JavaDoc home = System.getProperty("netbeans.user");
264         if (home != null && !"memory".equals(home) && !CLIOptions.noLogging) {
265             try {
266                 File JavaDoc dir = new File JavaDoc(new File JavaDoc(new File JavaDoc(home), "var"), "log");
267                 dir.mkdirs ();
268                 File JavaDoc f = new File JavaDoc(dir, "messages.log");
269                 File JavaDoc f1 = new File JavaDoc(dir, "messages.log.1");
270                 File JavaDoc f2 = new File JavaDoc(dir, "messages.log.2");
271
272                 if (f1.exists()) {
273                     f1.renameTo(f2);
274                 }
275                 if (f.exists()) {
276                     f.renameTo(f1);
277                 }
278                 
279                 FileOutputStream JavaDoc fout = new FileOutputStream JavaDoc(f, false);
280                 Handler JavaDoc h = new StreamHandler JavaDoc(fout, NbFormatter.FORMATTER);
281                 h.setLevel(Level.ALL);
282                 h.setFormatter(NbFormatter.FORMATTER);
283                 defaultHandler = new NonClose(h, 5000);
284             } catch (IOException JavaDoc ex) {
285                 ex.printStackTrace();
286             }
287         }
288         
289         if (defaultHandler == null) {
290             defaultHandler = streamHandler();
291             disabledConsole = true;
292         }
293         return defaultHandler;
294     }
295
296     /** Allows tests to flush all standard handlers */
297     static void flush(boolean clear) {
298         Handler JavaDoc s = streamHandler;
299         if (s != null) {
300             s.flush();
301         }
302
303         Handler JavaDoc d = defaultHandler;
304         if (d != null) {
305             d.flush();
306         }
307
308         if (clear) {
309             streamHandler = null;
310             defaultHandler = null;
311         }
312     }
313     static void close() {
314         Handler JavaDoc s = streamHandler;
315         if (s instanceof NonClose) {
316             NonClose ns = (NonClose)s;
317             ns.doClose();
318         }
319
320         Handler JavaDoc d = defaultHandler;
321         if (d != null) {
322             NonClose nd = (NonClose)d;
323             nd.doClose();
324         }
325     }
326
327     /** Non closing handler.
328      */

329     private static final class NonClose extends Handler JavaDoc
330     implements Runnable JavaDoc {
331         private static RequestProcessor RP = new RequestProcessor("Logging Flush"); // NOI18N
332

333         private final Handler JavaDoc delegate;
334         private RequestProcessor.Task flush;
335         private int delay;
336
337         public NonClose(Handler JavaDoc h, int delay) {
338             delegate = h;
339             flush = RP.create(this, true);
340             flush.setPriority(Thread.MIN_PRIORITY);
341             this.delay = delay;
342         }
343
344         public void publish(LogRecord JavaDoc record) {
345             delegate.publish(record);
346             flush.schedule(delay);
347         }
348
349         public void flush() {
350             flush.cancel();
351             flush.waitFinished();
352             delegate.flush();
353         }
354
355         public void close() throws SecurityException JavaDoc {
356             flush();
357             delegate.flush();
358         }
359
360         public void doClose() throws SecurityException JavaDoc {
361             flush();
362             delegate.close();
363         }
364
365         public Formatter JavaDoc getFormatter() {
366             return delegate.getFormatter();
367         }
368
369         static Handler JavaDoc getInternal(Handler JavaDoc h) {
370             if (h instanceof NonClose) {
371                 return ((NonClose)h).delegate;
372             }
373             return h;
374         }
375
376         public void run() {
377             delegate.flush();
378         }
379     }
380
381     /** Modified formater for use in NetBeans.
382      */

383     private static final class NbFormatter extends java.util.logging.Formatter JavaDoc {
384         private static String JavaDoc lineSeparator = System.getProperty ("line.separator"); // NOI18N
385
static java.util.logging.Formatter JavaDoc FORMATTER = new NbFormatter ();
386
387         
388         public String JavaDoc format(java.util.logging.LogRecord JavaDoc record) {
389             StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
390             print(sb, record, new HashSet JavaDoc<Throwable JavaDoc>());
391             return sb.toString();
392         }
393
394
395         private void print(StringBuilder JavaDoc sb, LogRecord JavaDoc record, Set JavaDoc<Throwable JavaDoc> beenThere) {
396             // XXX this is copied from NbErrorManager? why are we maintaining two copies? -jglick
397
String JavaDoc message = formatMessage(record);
398             if (message != null && message.indexOf('\n') != -1 && record.getThrown() == null) {
399                 // multi line messages print witout any wrappings
400
sb.append(message);
401                 return;
402             }
403             if ("stderr".equals(record.getLoggerName()) && record.getLevel() == Level.INFO) { // NOI18N
404
// do not prefix stderr logging...
405
sb.append(message);
406                 return;
407             }
408
409             sb.append(record.getLevel().getLocalizedName());
410             addLoggerName (sb, record);
411             if (message != null) {
412                 sb.append(": ");
413                 sb.append(message);
414             }
415             sb.append(lineSeparator);
416             if (record.getThrown() != null && record.getLevel().intValue() != 1973) { // 1973 signals ErrorManager.USER
417
try {
418                     StringWriter JavaDoc sw = new StringWriter JavaDoc();
419                     PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
420                     // All other kinds of throwables we check for a stack trace.
421
// First try to find where the throwable was caught.
422
StackTraceElement JavaDoc[] tStack = record.getThrown().getStackTrace();
423                     StackTraceElement JavaDoc[] hereStack = new Throwable JavaDoc().getStackTrace();
424                     int idx = -1;
425                     for (int i = 1; i <= Math.min(tStack.length, hereStack.length); i++) {
426                         if (!tStack[tStack.length - i].equals(hereStack[hereStack.length - i])) {
427                             idx = tStack.length - i + 1;
428                             break;
429                         }
430                     }
431                     String JavaDoc[] tLines = decompose(record.getThrown());
432                     for (int i = 0; i < tLines.length; i++) {
433                         if (i == idx) {
434                             pw.print("[catch]"); // NOI18N
435
// Also translate following tab -> space since formatting is bad in
436
// Output Window (#8104) and some mail agents screw it up etc.
437
if (tLines[i].charAt(0) == '\t') {
438                                 pw.print(' ');
439                                 tLines[i] = tLines[i].substring(1);
440                             }
441                         }
442                         pw.println(tLines[i]);
443                     }
444                     pw.close();
445                     sb.append(sw.toString());
446                 } catch (Exception JavaDoc ex) {
447                 }
448
449                 LogRecord JavaDoc[] arr = extractDelegates(sb, record.getThrown(), beenThere);
450                 if (arr != null) {
451                     for (LogRecord JavaDoc r : arr) {
452                         print(sb, r, beenThere);
453                     }
454                 }
455
456                 specialProcessing(sb, record.getThrown(), beenThere);
457             }
458         }
459         
460         private static void addLoggerName (StringBuilder JavaDoc sb, java.util.logging.LogRecord JavaDoc record) {
461             String JavaDoc name = record.getLoggerName ();
462             if (!"".equals (name)) {
463                 sb.append(" [");
464                 sb.append(name);
465                 sb.append(']');
466             }
467         }
468
469         private static LogRecord JavaDoc[] extractDelegates(StringBuilder JavaDoc sb, Throwable JavaDoc t, Set JavaDoc<Throwable JavaDoc> beenThere) {
470             if (!beenThere.add(t)) {
471                 sb.append("warning: cyclic dependency between annotated throwables"); // NOI18N
472
return null;
473             }
474
475             if (t instanceof Callable JavaDoc) {
476                 Object JavaDoc rec = null;
477                 try {
478                     rec = ((Callable JavaDoc) t).call();
479                 } catch (Exception JavaDoc ex) {
480                     ex.printStackTrace();
481                 }
482                 if (rec instanceof LogRecord JavaDoc[]) {
483                     return (LogRecord JavaDoc[])rec;
484                 }
485             }
486             if (t == null) {
487                 return null;
488             }
489             return extractDelegates(sb, t.getCause(), beenThere);
490         }
491
492
493         private void specialProcessing(StringBuilder JavaDoc sb, Throwable JavaDoc t, Set JavaDoc<Throwable JavaDoc> beenThere) {
494             // MissingResourceException should be printed nicely... --jglick
495
if (t instanceof MissingResourceException JavaDoc) {
496                 MissingResourceException JavaDoc mre = (MissingResourceException JavaDoc) t;
497                 String JavaDoc cn = mre.getClassName();
498                 if (cn != null) {
499                     LogRecord JavaDoc rec = new LogRecord JavaDoc(Level.CONFIG, null);
500                     rec.setResourceBundle(NbBundle.getBundle(TopLogging.class));
501                     rec.setMessage("EXC_MissingResourceException_class_name");
502                     rec.setParameters(new Object JavaDoc[] { cn });
503                     print(sb, rec, beenThere);
504                 }
505                 String JavaDoc k = mre.getKey();
506                 if (k != null) {
507                     LogRecord JavaDoc rec = new LogRecord JavaDoc(Level.CONFIG, null);
508                     rec.setResourceBundle(NbBundle.getBundle(TopLogging.class));
509                     rec.setMessage("EXC_MissingResourceException_key");
510                     rec.setParameters(new Object JavaDoc[] { k });
511                     print(sb, rec, beenThere);
512                 }
513             }
514             if (t instanceof SAXParseException JavaDoc) {
515                 // For some reason these fail to come with useful data, like location.
516
SAXParseException JavaDoc spe = (SAXParseException JavaDoc)t;
517                 String JavaDoc pubid = spe.getPublicId();
518                 String JavaDoc sysid = spe.getSystemId();
519                 if (pubid != null || sysid != null) {
520                     int col = spe.getColumnNumber();
521                     int line = spe.getLineNumber();
522                     String JavaDoc msg;
523                     Object JavaDoc[] param;
524                     if (col != -1 || line != -1) {
525                         msg = "EXC_sax_parse_col_line"; // NOI18N
526
param = new Object JavaDoc[] {String.valueOf(pubid), String.valueOf(sysid), new Integer JavaDoc(col), new Integer JavaDoc(line)};
527                     } else {
528                         msg = "EXC_sax_parse"; // NOI18N
529
param = new Object JavaDoc[] { String.valueOf(pubid), String.valueOf(sysid) };
530                     }
531                     LogRecord JavaDoc rec = new LogRecord JavaDoc(Level.CONFIG, null);
532                     rec.setResourceBundle(NbBundle.getBundle(TopLogging.class));
533                     rec.setMessage(msg);
534                     rec.setParameters(param);
535                     print(sb, rec, beenThere);
536                 }
537             }
538         }
539         /** Get a throwable's stack trace, decomposed into individual lines. */
540         private static String JavaDoc[] decompose(Throwable JavaDoc t) {
541             StringWriter JavaDoc sw = new StringWriter JavaDoc();
542             t.printStackTrace(new PrintWriter JavaDoc(sw));
543             return sw.toString().split("(\r\n?|\n)($|(?=\\s*at ))"); // NOI18N
544
}
545     } // end of NbFormater
546

547     /** a stream to delegate to logging.
548      */

549     private static final class LgStream extends PrintStream JavaDoc {
550         private Logger JavaDoc log;
551         private StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
552
553         public LgStream(Logger JavaDoc log) {
554             super(new ByteArrayOutputStream JavaDoc());
555             this.log = log;
556         }
557
558         public void write(byte[] buf, int off, int len) {
559             sb.append(new String JavaDoc(buf, off, len));
560             checkFlush();
561         }
562
563         public void write(byte[] b) throws IOException JavaDoc {
564             write(b, 0, b.length);
565         }
566
567         public void write(int b) {
568             sb.append((char)b);
569             checkFlush();
570         }
571
572         private void checkFlush() {
573             boolean justNewLine = false;
574             for (;;) {
575                 int first = sb.indexOf("\n"); // NOI18N
576
if (first < 0) {
577                     break;
578                 }
579                 justNewLine = false;
580                 if (first == 0) {
581                     justNewLine = true;
582                     sb.delete(0, 1);
583                     continue;
584                 }
585                 log.log(Level.INFO, sb.substring(0, first + 1));
586                 sb.delete(0, first + 1);
587             }
588             
589             if (justNewLine) {
590                 log.log(Level.INFO, "\n");
591             }
592         }
593     } // end of LgStream
594

595     private static final class LookupDel extends Handler JavaDoc
596     implements LookupListener {
597         private Lookup.Result<Handler JavaDoc> handlers;
598         private Collection JavaDoc<? extends Handler JavaDoc> instances;
599         
600         
601         public LookupDel() {
602             handlers = Lookup.getDefault().lookupResult(Handler JavaDoc.class);
603             instances = handlers.allInstances();
604             handlers.addLookupListener(this);
605         }
606         
607         
608         public void publish(LogRecord JavaDoc record) {
609             for (Handler JavaDoc h : instances) {
610                 h.publish(record);
611             }
612         }
613
614         public void flush() {
615             for (Handler JavaDoc h : instances) {
616                 h.flush();
617             }
618         }
619
620         public void close() throws SecurityException JavaDoc {
621             for (Handler JavaDoc h : instances) {
622                 h.close();
623             }
624         }
625
626         public void resultChanged(LookupEvent ev) {
627             instances = handlers.allInstances();
628         }
629     } // end of LookupDel
630

631     /** Instances are created in awt.EventDispatchThread */
632     public static final class AWTHandler {
633         /** The name MUST be handle and MUST be public */
634         public static void handle(Throwable JavaDoc t) {
635             // Either org.netbeans or org.netbeans.core.execution pkgs:
636
if (t.getClass().getName().endsWith(".ExitSecurityException")) { // NOI18N
637
return;
638             }
639             Logger.global.log(Level.SEVERE, null, t);
640         }
641     } // end of AWTHandler
642

643 }
644
Popular Tags