• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.tools.layoutlib.create;
18 
19 import java.io.PrintWriter;
20 import java.io.StringWriter;
21 
22 public class Log {
23 
24     private boolean mVerbose = false;
25 
setVerbose(boolean verbose)26     public void setVerbose(boolean verbose) {
27         mVerbose = verbose;
28     }
29 
debug(String format, Object... args)30     public void debug(String format, Object... args) {
31         if (mVerbose) {
32             info(format, args);
33         }
34     }
35 
36     /** Similar to debug() but doesn't do a \n automatically. */
debugNoln(String format, Object... args)37     public void debugNoln(String format, Object... args) {
38         if (mVerbose) {
39             String s = String.format(format, args);
40             System.out.print(s);
41         }
42     }
43 
info(String format, Object... args)44     public void info(String format, Object... args) {
45         String s = String.format(format, args);
46         outPrintln(s);
47     }
48 
error(String format, Object... args)49     public void error(String format, Object... args) {
50         String s = String.format(format, args);
51         errPrintln(s);
52     }
53 
exception(Throwable t, String format, Object... args)54     public void exception(Throwable t, String format, Object... args) {
55         StringWriter sw = new StringWriter();
56         PrintWriter pw = new PrintWriter(sw);
57         t.printStackTrace(pw);
58         pw.flush();
59         error(format + "\n" + sw.toString(), args);
60     }
61 
62     /** for unit testing */
errPrintln(String msg)63     protected void errPrintln(String msg) {
64         System.err.println(msg);
65     }
66 
67     /** for unit testing */
outPrintln(String msg)68     protected void outPrintln(String msg) {
69         System.out.println(msg);
70     }
71 
72 }
73