Debian Codegraph @

src/com/google/javascript/jscomp/LoggerErrorManager.java

raw symbols SCIP
1 /*
2 * Copyright 2007 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 import com.google.javascript.jscomp.CheckLevel;
20
21 import java.util.logging.Logger;
22 import java.util.logging.Level;
23
24 /**
25 * An error manager that logs errors and warnings using a logger in addition to
26 * collecting them in memory. Errors are logged at the SEVERE level and warnings
27 * are logged at the WARNING level.
28 *
29 */
30 public class LoggerErrorManager extends BasicErrorManager {
31 private final MessageFormatter formatter;
32 private final Logger logger;
33
34 /**
35 * Creates an instance.
36 */
37 public LoggerErrorManager(MessageFormatter formatter, Logger logger) {
38 this.formatter = formatter;
39 this.logger = logger;
40 }
41
42 /**
43 * Creates an instance with a source-less error formatter.
44 */
45 public LoggerErrorManager(Logger logger) {
46 this(ErrorFormat.SOURCELESS.toFormatter(null, false), logger);
47 }
48
49 @Override
50 public void println(CheckLevel level, JSError error) {
51 switch (level) {
52 case ERROR:
53 logger.severe(error.format(level, formatter));
54 break;
55 case WARNING:
56 logger.warning(error.format(level, formatter));
57 break;
58 case OFF:
59 break;
60 }
61 }
62
63 @Override
64 protected void printSummary() {
65 Level level = (getErrorCount() + getWarningCount() == 0) ?
66 Level.INFO : Level.WARNING;
67 if (getTypedPercent() > 0.0) {
68 logger.log(level, "{0} error(s), {1} warning(s), {2,number,#.#}% typed",
69 new Object[] {getErrorCount(), getWarningCount(), getTypedPercent()});
70 } else {
71 if (getErrorCount() + getWarningCount() > 0) {
72 logger.log(level, "{0} error(s), {1} warning(s)",
73 new Object[] {getErrorCount(), getWarningCount()});
74 }
75 }
76 }
77 }