01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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
36: .getInstance("CompilationServiceTest", 800, 600,
37: true);
38: AbstractTreeLogger atl = logWindow.getLogger();
39: new Thread(logWindow).start();
40: return maybeSetDetailLevel(atl);
41: } else {
42: return TreeLogger.NULL;
43: }
44: }
45:
46: public static void logURLs(TreeLogger logger, TreeLogger.Type type,
47: URL[] urls) {
48: for (int i = 0; i < urls.length; i++) {
49: URL url = urls[i];
50: logger.log(type, url.toExternalForm(), null);
51: }
52: }
53:
54: public static TreeLogger maybeSetDetailLevel(AbstractTreeLogger atl) {
55: String s = System.getProperty("gwt.logLevel");
56: if (s != null) {
57: TreeLogger.Type type = TreeLogger.Type.valueOf(s);
58: if (type != null) {
59: atl.setMaxDetail(type);
60: }
61: }
62: return atl;
63: }
64: }
|