| 1 |
/* |
| 2 |
* Copyright (C) 2011 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.example.android.render; |
| 18 |
|
| 19 |
import com.android.ide.common.log.ILogger; |
| 20 |
import com.android.ide.common.rendering.api.LayoutLog; |
| 21 |
import com.android.sdklib.ISdkLog; |
| 22 |
|
| 23 |
/** |
| 24 |
* Class implementing the 3 different log interface we use! |
| 25 |
* |
| 26 |
* At least ILogger and ISdkLog are identical... |
| 27 |
* |
| 28 |
*/ |
| 29 |
public class StdOutLogger extends LayoutLog implements ILogger, ISdkLog { |
| 30 |
|
| 31 |
// LayoutLog |
| 32 |
|
| 33 |
@Override |
| 34 |
public void error(String tag, String message, Object data) { |
| 35 |
if (tag != null) { |
| 36 |
System.err.println("ERROR: [" + tag + "] " + message); |
| 37 |
} else { |
| 38 |
System.err.println("ERROR: " + message); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public void error(String tag, String message, Throwable throwable, Object data) { |
| 44 |
error(tag, message, data); |
| 45 |
throwable.printStackTrace(); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public void fidelityWarning(String tag, String message, Throwable throwable, Object data) { |
| 50 |
if (tag != null) { |
| 51 |
System.out.println("warning: [" + tag + "] " + message); |
| 52 |
} else { |
| 53 |
System.out.println("warning: " + message); |
| 54 |
} |
| 55 |
if (throwable != null) { |
| 56 |
throwable.printStackTrace(); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public void warning(String tag, String message, Object data) { |
| 62 |
fidelityWarning(tag, message, null /*throwable*/, data); |
| 63 |
} |
| 64 |
|
| 65 |
// ILogger / ISdkLog |
| 66 |
|
| 67 |
public void error(Throwable t, String errorFormat, Object... args) { |
| 68 |
error(null /*tag*/, String.format(errorFormat, args), t, null /*data*/); |
| 69 |
} |
| 70 |
|
| 71 |
public void printf(String msgFormat, Object... args) { |
| 72 |
System.out.println(String.format(msgFormat, args)); |
| 73 |
} |
| 74 |
|
| 75 |
public void warning(String warningFormat, Object... args) { |
| 76 |
warning(null /*tag*/, String.format(warningFormat, args), null /*data*/); |
| 77 |
} |
| 78 |
} |