diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-10-23 20:33:11 -0400 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-10-23 20:33:11 -0400 |
commit | 4453050e1be622cb1b5abcd00356f7a7fe40916b (patch) | |
tree | 6a3ff98458184bfbce5ce95471c0dd8d0d18f452 /dalvik/src | |
parent | 59586fdc368dc21f0898716dbd4eb3ebd7e370d1 (diff) | |
parent | c99250a4d619670f2a9410df121eff04fdc9e87c (diff) | |
download | libcore-4453050e1be622cb1b5abcd00356f7a7fe40916b.zip libcore-4453050e1be622cb1b5abcd00356f7a7fe40916b.tar.gz libcore-4453050e1be622cb1b5abcd00356f7a7fe40916b.tar.bz2 |
Merge change I410514c5
* changes:
Expose hooks for more efficient log handling in Android apps.
Diffstat (limited to 'dalvik/src')
-rw-r--r-- | dalvik/src/main/java/dalvik/system/DalvikLogHandler.java | 47 | ||||
-rw-r--r-- | dalvik/src/main/java/dalvik/system/DalvikLogging.java | 48 |
2 files changed, 95 insertions, 0 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DalvikLogHandler.java b/dalvik/src/main/java/dalvik/system/DalvikLogHandler.java new file mode 100644 index 0000000..a62ca3b --- /dev/null +++ b/dalvik/src/main/java/dalvik/system/DalvikLogHandler.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2009 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 dalvik.system; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An optimized handler for efficient publishing of basic log messages. + * Implementers should also be subclasses of {@link java.util.logging.Handler}. + * + * <p>Unlike the default log handler, this API doesn't require intermediate + * objects to be allocated for log handling. It also includes a short tag, which + * may otherwise need to be calculated for each published message. + * + * @hide + */ +public interface DalvikLogHandler { + + /** + * Publishes a log message. Unlike {@link + * java.util.logging.Handler#publish(java.util.logging.LogRecord)}, this + * method includes only the raw log message. Log messages that were created + * with additional fields (parameters, source methods, etc.) will flow + * through the conventional channels instead. + * + * @param tag the short (23 characters or fewer) logger tag identifying + * {@code logger}. + */ + void publish(Logger source, String tag, Level level, String message); + + // TODO: support messages with throwables? +}
\ No newline at end of file diff --git a/dalvik/src/main/java/dalvik/system/DalvikLogging.java b/dalvik/src/main/java/dalvik/system/DalvikLogging.java new file mode 100644 index 0000000..b5c7ad5 --- /dev/null +++ b/dalvik/src/main/java/dalvik/system/DalvikLogging.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2009 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 dalvik.system; + +/** + * Utility methods for logging to {@code DalvikHandlers}. + * + * @hide + */ +public final class DalvikLogging { + private DalvikLogging() {} + + /** + * Returns the short logger tag (up to 23 chars) for the given logger name. + * Traditionally loggers are named by fully-qualified Java classes; this + * method attempts to return a concise identifying part of such names. + */ + public static String loggerNameToTag(String loggerName) { + // Anonymous logger. + if (loggerName == null) { + return "null"; + } + + int length = loggerName.length(); + if (length <= 23) { + return loggerName; + } + + int lastPeriod = loggerName.lastIndexOf("."); + return length - (lastPeriod + 1) <= 23 + ? loggerName.substring(lastPeriod + 1) + : loggerName.substring(loggerName.length() - 23); + } +} |