Log.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2008 The Android Open Source Project 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 17package com.android.tools.layoutlib.create; 18 19import java.io.PrintWriter; 20import java.io.StringWriter; 21 22public class Log { 23 24 private boolean mVerbose = false; 25 26 public void setVerbose(boolean verbose) { 27 mVerbose = verbose; 28 } 29 30 public void debug(String format, Object... args) { 31 if (mVerbose) { 32 info(format, args); 33 } 34 } 35 36 public void info(String format, Object... args) { 37 String s = String.format(format, args); 38 outPrintln(s); 39 } 40 41 public void error(String format, Object... args) { 42 String s = String.format(format, args); 43 errPrintln(s); 44 } 45 46 public void exception(Throwable t, String format, Object... args) { 47 StringWriter sw = new StringWriter(); 48 PrintWriter pw = new PrintWriter(sw); 49 t.printStackTrace(pw); 50 pw.flush(); 51 error(format + "\n" + sw.toString(), args); 52 } 53 54 /** for unit testing */ 55 protected void errPrintln(String msg) { 56 System.err.println(msg); 57 } 58 59 /** for unit testing */ 60 protected void outPrintln(String msg) { 61 System.out.println(msg); 62 } 63 64} 65