blob: 68f64d0dde4b6adddddc0f9a1cad5a3e6cf5a6e8 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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 android.util;
18
19/**
20 * Implementation of a {@link android.util.Printer} that sends its output
21 * to the system log.
22 */
23public class LogPrinter implements Printer {
24 private final int mPriority;
25 private final String mTag;
Joe Onorato8a9b2202010-02-26 18:56:32 -080026 private final int mBuffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28 /**
29 * Create a new Printer that sends to the log with the given priority
30 * and tag.
31 *
32 * @param priority The desired log priority:
33 * {@link android.util.Log#VERBOSE Log.VERBOSE},
34 * {@link android.util.Log#DEBUG Log.DEBUG},
35 * {@link android.util.Log#INFO Log.INFO},
36 * {@link android.util.Log#WARN Log.WARN}, or
37 * {@link android.util.Log#ERROR Log.ERROR}.
38 * @param tag A string tag to associate with each printed log statement.
39 */
40 public LogPrinter(int priority, String tag) {
41 mPriority = priority;
42 mTag = tag;
Joe Onorato8a9b2202010-02-26 18:56:32 -080043 mBuffer = Log.LOG_ID_MAIN;
44 }
45
46 /**
47 * @hide
48 * Same as above, but buffer is one of the LOG_ID_ constants from android.util.Log.
49 */
50 public LogPrinter(int priority, String tag, int buffer) {
51 mPriority = priority;
52 mTag = tag;
53 mBuffer = buffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 }
55
56 public void println(String x) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080057 Log.println_native(mBuffer, mPriority, mTag, x);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 }
59}