Log.java revision 2593:035b01d356ee
1/* 2 * Copyright (c) 2012, 2014, 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 26package com.sun.tools.sjavac; 27 28import 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 risk. 36 * This code and its internal interfaces are subject to change or 37 * deletion without notice.</b> 38 */ 39public 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 initializeLog(PrintStream o, PrintStream e) { 75 out = o; 76 err = e; 77 } 78 79 static public void setLogLevel(String l) { 80 switch (l) { 81 case "warn": level = WARN; break; 82 case "info": level = INFO; break; 83 case "debug": level = DEBUG; break; 84 case "trace": level = TRACE; break; 85 default: 86 throw new IllegalArgumentException("No such log level \"" + l + "\""); 87 } 88 } 89 90 static public boolean isTracing() { 91 return level >= TRACE; 92 } 93 94 static public boolean isDebugging() { 95 return level >= DEBUG; 96 } 97} 98