2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.support.v2.util;
19 import android.util.Log;
21 import java.io.Writer;
24 * Useful logging utility that is not available on all versions of Android.
26 public class LogWriter extends Writer {
27 private final String mTag;
28 private StringBuilder mBuilder = new StringBuilder(128);
31 * Create a new Writer that sends to the log with the given priority
34 * @param priority The desired log priority:
35 * {@link android.util.Log#VERBOSE Log.VERBOSE},
36 * {@link android.util.Log#DEBUG Log.DEBUG},
37 * {@link android.util.Log#INFO Log.INFO},
38 * {@link android.util.Log#WARN Log.WARN}, or
39 * {@link android.util.Log#ERROR Log.ERROR}.
40 * @param tag A string tag to associate with each printed log statement.
42 public LogWriter(String tag) {
46 @Override public void close() {
50 @Override public void flush() {
54 @Override public void write(char[] buf, int offset, int count) {
55 for(int i = 0; i < count; i++) {
56 char c = buf[offset + i];
66 private void flushBuilder() {
67 if (mBuilder.length() > 0) {
68 Log.d(mTag, mBuilder.toString());
69 mBuilder.delete(0, mBuilder.length());