Merge "Add new Slog class."

This commit is contained in:
Joe Onorato
2010-03-01 13:03:52 -08:00
committed by Android (Google) Code Review
3 changed files with 122 additions and 18 deletions

View File

@@ -98,7 +98,7 @@ public final class Log {
* @param msg The message you would like logged.
*/
public static int v(String tag, String msg) {
return println(VERBOSE, tag, msg);
return println_native(LOG_ID_MAIN, VERBOSE, tag, msg);
}
/**
@@ -109,7 +109,7 @@ public final class Log {
* @param tr An exception to log
*/
public static int v(String tag, String msg, Throwable tr) {
return println(VERBOSE, tag, msg + '\n' + getStackTraceString(tr));
return println_native(LOG_ID_MAIN, VERBOSE, tag, msg + '\n' + getStackTraceString(tr));
}
/**
@@ -119,7 +119,7 @@ public final class Log {
* @param msg The message you would like logged.
*/
public static int d(String tag, String msg) {
return println(DEBUG, tag, msg);
return println_native(LOG_ID_MAIN, DEBUG, tag, msg);
}
/**
@@ -130,7 +130,7 @@ public final class Log {
* @param tr An exception to log
*/
public static int d(String tag, String msg, Throwable tr) {
return println(DEBUG, tag, msg + '\n' + getStackTraceString(tr));
return println_native(LOG_ID_MAIN, DEBUG, tag, msg + '\n' + getStackTraceString(tr));
}
/**
@@ -140,7 +140,7 @@ public final class Log {
* @param msg The message you would like logged.
*/
public static int i(String tag, String msg) {
return println(INFO, tag, msg);
return println_native(LOG_ID_MAIN, INFO, tag, msg);
}
/**
@@ -151,7 +151,7 @@ public final class Log {
* @param tr An exception to log
*/
public static int i(String tag, String msg, Throwable tr) {
return println(INFO, tag, msg + '\n' + getStackTraceString(tr));
return println_native(LOG_ID_MAIN, INFO, tag, msg + '\n' + getStackTraceString(tr));
}
/**
@@ -161,7 +161,7 @@ public final class Log {
* @param msg The message you would like logged.
*/
public static int w(String tag, String msg) {
return println(WARN, tag, msg);
return println_native(LOG_ID_MAIN, WARN, tag, msg);
}
/**
@@ -172,7 +172,7 @@ public final class Log {
* @param tr An exception to log
*/
public static int w(String tag, String msg, Throwable tr) {
return println(WARN, tag, msg + '\n' + getStackTraceString(tr));
return println_native(LOG_ID_MAIN, WARN, tag, msg + '\n' + getStackTraceString(tr));
}
/**
@@ -202,7 +202,7 @@ public final class Log {
* @param tr An exception to log
*/
public static int w(String tag, Throwable tr) {
return println(WARN, tag, getStackTraceString(tr));
return println_native(LOG_ID_MAIN, WARN, tag, getStackTraceString(tr));
}
/**
@@ -212,7 +212,7 @@ public final class Log {
* @param msg The message you would like logged.
*/
public static int e(String tag, String msg) {
return println(ERROR, tag, msg);
return println_native(LOG_ID_MAIN, ERROR, tag, msg);
}
/**
@@ -223,7 +223,7 @@ public final class Log {
* @param tr An exception to log
*/
public static int e(String tag, String msg, Throwable tr) {
return println(ERROR, tag, msg + '\n' + getStackTraceString(tr));
return println_native(LOG_ID_MAIN, ERROR, tag, msg + '\n' + getStackTraceString(tr));
}
/**
@@ -258,7 +258,7 @@ public final class Log {
*/
public static int wtf(String tag, String msg, Throwable tr) {
tr = new TerribleFailure(msg, tr);
int bytes = println(ASSERT, tag, getStackTraceString(tr));
int bytes = println_native(LOG_ID_MAIN, ASSERT, tag, getStackTraceString(tr));
RuntimeInit.wtf(tag, tr);
return bytes;
}
@@ -285,5 +285,14 @@ public final class Log {
* @param msg The message you would like logged.
* @return The number of bytes written.
*/
public static native int println(int priority, String tag, String msg);
public static int println(int priority, String tag, String msg) {
return println_native(LOG_ID_MAIN, priority, tag, msg);
}
static final int LOG_ID_MAIN = 0;
static final int LOG_ID_RADIO = 1;
static final int LOG_ID_EVENTS = 2;
static final int LOG_ID_SYSTEM = 3;
static native int println_native(int bufID, int priority, String tag, String msg);
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.util;
import com.android.internal.os.RuntimeInit;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* @hide
*/
public final class Slog {
private Slog() {
}
public static int v(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag, msg);
}
public static int v(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int d(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag, msg);
}
public static int d(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int i(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag, msg);
}
public static int i(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int w(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, msg);
}
public static int w(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int w(String tag, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, Log.getStackTraceString(tr));
}
public static int e(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag, msg);
}
public static int e(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int println(int priority, String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, priority, tag, msg);
}
}

View File

@@ -98,10 +98,10 @@ static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring
/*
* In class android.util.Log:
* public static native int println(int priority, String tag, String msg)
* public static native int println_native(int buffer, int priority, String tag, String msg)
*/
static jint android_util_Log_println(JNIEnv* env, jobject clazz,
jint priority, jstring tagObj, jstring msgObj)
static jint android_util_Log_println_native(JNIEnv* env, jobject clazz,
jint bufID, jint priority, jstring tagObj, jstring msgObj)
{
const char* tag = NULL;
const char* msg = NULL;
@@ -116,11 +116,21 @@ static jint android_util_Log_println(JNIEnv* env, jobject clazz,
return -1;
}
if (bufID < 0 || bufID >= LOG_ID_MAX) {
jclass npeClazz;
npeClazz = env->FindClass("java/lang/NullPointerException");
assert(npeClazz != NULL);
env->ThrowNew(npeClazz, "bad bufID");
return -1;
}
if (tagObj != NULL)
tag = env->GetStringUTFChars(tagObj, NULL);
msg = env->GetStringUTFChars(msgObj, NULL);
int res = android_writeLog((android_LogPriority) priority, tag, msg);
int res = __android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);
if (tag != NULL)
env->ReleaseStringUTFChars(tagObj, tag);
@@ -135,7 +145,7 @@ static jint android_util_Log_println(JNIEnv* env, jobject clazz,
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
{ "isLoggable", "(Ljava/lang/String;I)Z", (void*) android_util_Log_isLoggable },
{ "println", "(ILjava/lang/String;Ljava/lang/String;)I", (void*) android_util_Log_println },
{ "println_native", "(IILjava/lang/String;Ljava/lang/String;)I", (void*) android_util_Log_println_native },
};
int register_android_util_Log(JNIEnv* env)