langtools/src/share/classes/com/sun/tools/sjavac/Log.java
changeset 15368 2577ddb7e710
child 22448 a85fbad9d687
child 22159 682da512ec17
equal deleted inserted replaced
15367:31b57f2b8d0b 15368:2577ddb7e710
       
     1 /*
       
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.tools.sjavac;
       
    27 
       
    28 import java.io.PrintStream;
       
    29 
       
    30 /**
       
    31  * Utility class only for sjavac logging.
       
    32  * The log level can be set using for example --log=DEBUG on the sjavac command line.
       
    33  *
       
    34  * <p><b>This is NOT part of any supported API.
       
    35  * If you write code that depends on this, you do so at your own
       
    36  * risk.  This code and its internal interfaces are subject to change
       
    37  * or deletion without notice.</b></p>
       
    38  */
       
    39 public class Log {
       
    40     private static PrintStream out, err;
       
    41 
       
    42     public final static int WARN = 1;
       
    43     public final static int INFO = 2;
       
    44     public final static int DEBUG = 3;
       
    45     public final static int TRACE = 4;
       
    46     private static int level = WARN;
       
    47 
       
    48     static public void trace(String msg) {
       
    49         if (level >= TRACE) {
       
    50             out.println(msg);
       
    51         }
       
    52     }
       
    53 
       
    54     static public void debug(String msg) {
       
    55         if (level >= DEBUG) {
       
    56             out.println(msg);
       
    57         }
       
    58     }
       
    59 
       
    60     static public void info(String msg) {
       
    61         if (level >= INFO) {
       
    62             out.println(msg);
       
    63         }
       
    64     }
       
    65 
       
    66     static public void warn(String msg) {
       
    67         err.println(msg);
       
    68     }
       
    69 
       
    70     static public void error(String msg) {
       
    71         err.println(msg);
       
    72     }
       
    73 
       
    74     static public void setLogLevel(String l, PrintStream o, PrintStream e)
       
    75         throws ProblemException {
       
    76         out = o;
       
    77         err = e;
       
    78         if (l.equals("warn")) level = WARN;
       
    79         else if (l.equals("info")) level = INFO;
       
    80         else if (l.equals("debug")) level = DEBUG;
       
    81         else if (l.equals("trace")) level = TRACE;
       
    82         else throw new ProblemException("No such log level \""+l+"\"");
       
    83     }
       
    84 
       
    85     static public boolean isTracing() {
       
    86         return level >= TRACE;
       
    87     }
       
    88 
       
    89     static public boolean isDebugging() {
       
    90         return level >= DEBUG;
       
    91     }
       
    92 }