KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2007 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 com.google.gwt.core.ext.TreeLogger;
19
20 import java.net.URL JavaDoc;
21
22 /**
23  * Utility methods for creating various sorts of loggers.
24  */

25 public class Loggers {
26
27   /**
28    * Produces either a null logger or, if the property
29    * <code>gwt.useGuiLogger</code> is set, a graphical tree logger. This
30    * method is useful for unit tests, where most of the time you don't want to
31    * log.
32    */

33   public static TreeLogger createOptionalGuiTreeLogger() {
34     if (System.getProperty("gwt.useGuiLogger") != null) {
35        DetachedTreeLoggerWindow logWindow = DetachedTreeLoggerWindow.getInstance(
36           "CompilationServiceTest", 800, 600, true);
37        AbstractTreeLogger atl = logWindow.getLogger();
38        new Thread JavaDoc(logWindow).start();
39       return maybeSetDetailLevel(atl);
40     } else {
41       return TreeLogger.NULL;
42     }
43   }
44
45   public static void logURLs(TreeLogger logger, TreeLogger.Type type, URL JavaDoc[] urls) {
46     for (int i = 0; i < urls.length; i++) {
47       URL JavaDoc url = urls[i];
48       logger.log(type, url.toExternalForm(), null);
49     }
50   }
51
52   public static TreeLogger maybeSetDetailLevel(AbstractTreeLogger atl) {
53     String JavaDoc s = System.getProperty("gwt.logLevel");
54     if (s != null) {
55       TreeLogger.Type type = TreeLogger.Type.valueOf(s);
56       if (type != null) {
57         atl.setMaxDetail(type);
58       }
59     }
60     return atl;
61   }
62 }
63
Popular Tags