summaryrefslogtreecommitdiffstats
path: root/logging
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2009-05-11 19:08:46 -0700
committerJesse Wilson <jessewilson@google.com>2009-05-11 19:08:46 -0700
commit9a0fbe99031759393563ee69ac4640f66f182686 (patch)
tree99865da7d37c745ce9f293a29322ae1c67def4e0 /logging
parent4031b57a9518fc2ad73ec001aa5d968e446fa978 (diff)
downloadlibcore-9a0fbe99031759393563ee69ac4640f66f182686.zip
libcore-9a0fbe99031759393563ee69ac4640f66f182686.tar.gz
libcore-9a0fbe99031759393563ee69ac4640f66f182686.tar.bz2
Bringing the logging module up to Harmony r772995.
commit 080ff677c719f1e53ffb544c3fb684bb9ff28677 Author: Jesse Wilson <jessewilson@google.com> Date: Mon May 11 19:06:05 2009 -0700 Copied test changes over manually. commit ea52f28de5378f7dd4eff5c0f83d805e997a98de Merge: 0c1f753 a6c8255 Author: Jesse Wilson <jessewilson@google.com> Date: Mon May 11 18:49:28 2009 -0700 Merge branch 'logging_772995' into logging_dalvik Conflicts: libcore/logging/.classpath libcore/logging/META-INF/MANIFEST.MF libcore/logging/build.xml libcore/logging/src/main/java/java/util/logging/ConsoleHandler.java libcore/logging/src/main/java/java/util/logging/FileHandler.java libcore/logging/src/main/java/java/util/logging/Formatter.java libcore/logging/src/main/java/java/util/logging/Handler.java libcore/logging/src/main/java/java/util/logging/Level.java libcore/logging/src/main/java/java/util/logging/LogManager.java libcore/logging/src/main/java/java/util/logging/LogRecord.java libcore/logging/src/main/java/java/util/logging/Logger.java libcore/logging/src/main/java/java/util/logging/LoggingMXBean.java libcore/logging/src/main/java/java/util/logging/LoggingPermission.java libcore/logging/src/main/java/java/util/logging/MemoryHandler.java libcore/logging/src/main/java/java/util/logging/SimpleFormatter.java libcore/logging/src/main/java/java/util/logging/SocketHandler.java libcore/logging/src/main/java/java/util/logging/StreamHandler.java libcore/logging/src/main/java/java/util/logging/XMLFormatter.java libcore/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java commit 0c1f7538e6fe3091a3d142b2ac14f5bf338b3a55 Author: Jesse Wilson <jessewilson@google.com> Date: Mon May 11 16:06:59 2009 -0700 Stripped @since Android 1.0 commit 4c715c6c58080b3cbed2928cd1b71b9931e217a3 Author: Jesse Wilson <jessewilson@google.com> Date: Mon May 11 15:57:59 2009 -0700 Logging Dalvik. commit a6c8255dbbad85145a2066d9846d24787df0f75f Author: Jesse Wilson <jessewilson@google.com> Date: Mon May 11 15:56:41 2009 -0700 Logging 772995 commit db77dbdf56e99e3dcced2d758f7150007562c41c Author: Jesse Wilson <jessewilson@google.com> Date: Mon May 11 15:54:13 2009 -0700 Logging 527399
Diffstat (limited to 'logging')
-rw-r--r--logging/src/main/java/java/util/logging/ConsoleHandler.java13
-rw-r--r--logging/src/main/java/java/util/logging/ErrorManager.java22
-rw-r--r--logging/src/main/java/java/util/logging/FileHandler.java80
-rw-r--r--logging/src/main/java/java/util/logging/Filter.java3
-rw-r--r--logging/src/main/java/java/util/logging/Formatter.java35
-rw-r--r--logging/src/main/java/java/util/logging/Handler.java100
-rw-r--r--logging/src/main/java/java/util/logging/Level.java78
-rw-r--r--logging/src/main/java/java/util/logging/LogManager.java229
-rw-r--r--logging/src/main/java/java/util/logging/LogRecord.java111
-rw-r--r--logging/src/main/java/java/util/logging/Logger.java320
-rw-r--r--logging/src/main/java/java/util/logging/LoggingMXBean.java17
-rw-r--r--logging/src/main/java/java/util/logging/LoggingPermission.java16
-rw-r--r--logging/src/main/java/java/util/logging/MemoryHandler.java128
-rw-r--r--logging/src/main/java/java/util/logging/SimpleFormatter.java13
-rw-r--r--logging/src/main/java/java/util/logging/SocketHandler.java16
-rw-r--r--logging/src/main/java/java/util/logging/StreamHandler.java71
-rw-r--r--logging/src/main/java/java/util/logging/XMLFormatter.java136
-rw-r--r--logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java22
-rw-r--r--logging/src/test/resources/config/java/util/logging/logging.config2
19 files changed, 548 insertions, 864 deletions
diff --git a/logging/src/main/java/java/util/logging/ConsoleHandler.java b/logging/src/main/java/java/util/logging/ConsoleHandler.java
index a88cf0c..ef365ca 100644
--- a/logging/src/main/java/java/util/logging/ConsoleHandler.java
+++ b/logging/src/main/java/java/util/logging/ConsoleHandler.java
@@ -38,19 +38,13 @@ package java.util.logging;
* handler will use to encode log messages, defaults to {@code null} if this
* property is not found or has an invalid value.
* </ul>
- * </p>
* <p>
* This class is not thread-safe.
- * </p>
- *
- * @since Android 1.0
*/
public class ConsoleHandler extends StreamHandler {
/**
* Constructs a {@code ConsoleHandler} object.
- *
- * @since Android 1.0
*/
public ConsoleHandler() {
super(System.err);
@@ -58,8 +52,6 @@ public class ConsoleHandler extends StreamHandler {
/**
* Closes this handler. The {@code System.err} is flushed but not closed.
- *
- * @since Android 1.0
*/
@Override
public void close() {
@@ -68,16 +60,13 @@ public class ConsoleHandler extends StreamHandler {
/**
* Logs a record if necessary. A flush operation will be done.
- *
+ *
* @param record
* the log record to be logged.
- *
- * @since Android 1.0
*/
@Override
public void publish(LogRecord record) {
super.publish(record);
super.flush();
-
}
}
diff --git a/logging/src/main/java/java/util/logging/ErrorManager.java b/logging/src/main/java/java/util/logging/ErrorManager.java
index 6f5084c..708ddfa 100644
--- a/logging/src/main/java/java/util/logging/ErrorManager.java
+++ b/logging/src/main/java/java/util/logging/ErrorManager.java
@@ -24,51 +24,37 @@ import org.apache.harmony.logging.internal.nls.Messages;
* error that may happen during logging. {@code Handlers} should report errors
* to an {@code ErrorManager}, instead of throwing exceptions, which would
* interfere with the log issuer's execution.
- *
- * @since Android 1.0
*/
public class ErrorManager {
/**
* The error code indicating a failure that does not fit in any of the
* specific types of failures that follow.
- *
- * @since Android 1.0
*/
public static final int GENERIC_FAILURE = 0;
/**
* The error code indicating a failure when writing to an output stream.
- *
- * @since Android 1.0
*/
public static final int WRITE_FAILURE = 1;
/**
* The error code indicating a failure when flushing an output stream.
- *
- * @since Android 1.0
*/
public static final int FLUSH_FAILURE = 2;
/**
* The error code indicating a failure when closing an output stream.
- *
- * @since Android 1.0
*/
public static final int CLOSE_FAILURE = 3;
/**
* The error code indicating a failure when opening an output stream.
- *
- * @since Android 1.0
*/
public static final int OPEN_FAILURE = 4;
/**
* The error code indicating a failure when formatting the error messages.
- *
- * @since Android 1.0
*/
public static final int FORMAT_FAILURE = 5;
@@ -85,20 +71,16 @@ public class ErrorManager {
/**
* Constructs an instance of {@code ErrorManager}.
- *
- * @since Android 1.0
*/
public ErrorManager() {
super();
}
/**
- * <p>
* Reports an error using the given message, exception and error code. This
* implementation will write out the message to {@link System#err} on the
* first call and all subsequent calls are ignored. A subclass of this class
* should override this method.
- * </p>
*
* @param message
* the error message, which may be {@code null}.
@@ -108,8 +90,6 @@ public class ErrorManager {
* @param errorCode
* the error code that identifies the type of error; see the
* constant fields of this class for possible values.
- *
- * @since Android 1.0
*/
public void error(String message, Exception exception, int errorCode) {
synchronized (this) {
@@ -119,7 +99,7 @@ public class ErrorManager {
called = true;
}
System.err.println(this.getClass().getName()
- + ": " + FAILURES[errorCode]); //$NON-NLS-1$
+ + ": " + FAILURES[errorCode]); //$NON-NLS-1$
if (message != null) {
// logging.1E=Error message - {0}
System.err.println(Messages.getString("logging.1E", message)); //$NON-NLS-1$
diff --git a/logging/src/main/java/java/util/logging/FileHandler.java b/logging/src/main/java/java/util/logging/FileHandler.java
index af71a6d..e1eba9e 100644
--- a/logging/src/main/java/java/util/logging/FileHandler.java
+++ b/logging/src/main/java/java/util/logging/FileHandler.java
@@ -38,48 +38,45 @@ import org.apache.harmony.logging.internal.nls.Messages;
* When a set of files is used and a given amount of data has been written to
* one file, then this file is closed and another file is opened. The name of
* these files are generated by given name pattern, see below for details.
- * </p>
+ * When the files have all been filled the Handler returns to the first and goes
+ * through the set again.
* <p>
* By default, the I/O buffering mechanism is enabled, but when each log record
* is complete, it is flushed out.
- * </p>
* <p>
* {@code XMLFormatter} is the default formatter for {@code FileHandler}.
- * </p>
* <p>
* {@code FileHandler} reads the following {@code LogManager} properties for
* initialization; if a property is not defined or has an invalid value, a
* default value is used.
* <ul>
- * <li>java.util.logging.FileHandler.level specifies the level for this
- * {@code Handler}, defaults to {@code Level.ALL}.</li>
+ * <li>java.util.logging.FileHandler.append specifies whether this
+ * {@code FileHandler} should append onto existing files, defaults to
+ * {@code false}.</li>
+ * <li>java.util.logging.FileHandler.count specifies how many output files to
+ * rotate, defaults to 1.</li>
* <li>java.util.logging.FileHandler.filter specifies the {@code Filter} class
* name, defaults to no {@code Filter}.</li>
* <li>java.util.logging.FileHandler.formatter specifies the {@code Formatter}
* class, defaults to {@code java.util.logging.XMLFormatter}.</li>
* <li>java.util.logging.FileHandler.encoding specifies the character set
* encoding name, defaults to the default platform encoding.</li>
+ * <li>java.util.logging.FileHandler.level specifies the level for this
+ * {@code Handler}, defaults to {@code Level.ALL}.</li>
* <li>java.util.logging.FileHandler.limit specifies the maximum number of
* bytes to write to any one file, defaults to zero, which means no limit.</li>
- * <li>java.util.logging.FileHandler.count specifies how many output files to
- * rotate, defaults to 1.</li>
* <li>java.util.logging.FileHandler.pattern specifies name pattern for the
* output files. See below for details. Defaults to "%h/java%u.log".</li>
- * <li>java.util.logging.FileHandler.append specifies whether this
- * {@code FileHandler} should append onto existing files, defaults to
- * {@code false}.</li>
* </ul>
- * </p>
* <p>
* Name pattern is a string that may include some special substrings, which will
* be replaced to generate output files:
- * </p>
* <ul>
* <li>"/" represents the local pathname separator</li>
- * <li>"%t" represents the system's temporary directory</li>
+ * <li>"%g" represents the generation number to distinguish rotated logs</li>
* <li>"%h" represents the home directory of the current user, which is
* specified by "user.home" system property</li>
- * <li>"%g" represents the generation number to distinguish rotated logs</li>
+ * <li>"%t" represents the system's temporary directory</li>
* <li>"%u" represents a unique number to resolve conflicts</li>
* <li>"%%" represents the percent sign character '%'</li>
* </ul>
@@ -88,7 +85,6 @@ import org.apache.harmony.logging.internal.nls.Messages;
* follow the sequence 0, 1, 2.... If the file count is larger than one, but the
* generation field("%g") has not been specified in the pattern, then the
* generation number after a dot will be added to the end of the file name.
- * </p>
* <p>
* The "%u" unique field is used to avoid conflicts and is set to 0 at first. If
* one {@code FileHandler} tries to open the filename which is currently in use
@@ -98,8 +94,6 @@ import org.apache.harmony.logging.internal.nls.Messages;
* value will be added to the end of the filename in question immediately to the
* right of a dot. The generation of unique IDs for avoiding conflicts is only
* guaranteed to work reliably when using a local disk file system.
- * </p>
- * @since Android 1.0
*/
public class FileHandler extends StreamHandler {
@@ -150,7 +144,7 @@ public class FileHandler extends StreamHandler {
/**
* Construct a {@code FileHandler} using {@code LogManager} properties or
* their default value.
- *
+ *
* @throws IOException
* if any I/O error occurs.
* @throws SecurityException
@@ -159,7 +153,6 @@ public class FileHandler extends StreamHandler {
* handler; required permissions include
* {@code LogPermission("control")},
* {@code FilePermission("write")} etc.
- * @since Android 1.0
*/
public FileHandler() throws IOException {
init(null, null, null, null);
@@ -232,21 +225,22 @@ public class FileHandler extends StreamHandler {
setOutputStream(output);
}
+ @SuppressWarnings("nls")
private void initProperties(String p, Boolean a, Integer l, Integer c) {
- super.initProperties("ALL", null, "java.util.logging.XMLFormatter", //$NON-NLS-1$//$NON-NLS-2$
+ super.initProperties("ALL", null, "java.util.logging.XMLFormatter",
null);
String className = this.getClass().getName();
- pattern = (null == p) ? getStringProperty(className + ".pattern", //$NON-NLS-1$
+ pattern = (null == p) ? getStringProperty(className + ".pattern",
DEFAULT_PATTERN) : p;
- if (null == pattern || "".equals(pattern)) { //$NON-NLS-1$
+ if (null == pattern || "".equals(pattern)) {
// logging.19=Pattern cannot be empty
- throw new NullPointerException(Messages.getString("logging.19")); //$NON-NLS-1$
+ throw new NullPointerException(Messages.getString("logging.19"));
}
- append = (null == a) ? getBooleanProperty(className + ".append", //$NON-NLS-1$
+ append = (null == a) ? getBooleanProperty(className + ".append",
DEFAULT_APPEND) : a.booleanValue();
- count = (null == c) ? getIntProperty(className + ".count", //$NON-NLS-1$
+ count = (null == c) ? getIntProperty(className + ".count",
DEFAULT_COUNT) : c.intValue();
- limit = (null == l) ? getIntProperty(className + ".limit", //$NON-NLS-1$
+ limit = (null == l) ? getIntProperty(className + ".limit",
DEFAULT_LIMIT) : l.intValue();
count = count < 1 ? DEFAULT_COUNT : count;
limit = limit < 0 ? DEFAULT_LIMIT : limit;
@@ -279,7 +273,7 @@ public class FileHandler extends StreamHandler {
/**
* Transform the pattern to the valid file name, replacing any patterns, and
* applying generation and uniqueID if present.
- *
+ *
* @param gen
* generation of this file
* @return transformed filename ready for use.
@@ -396,9 +390,9 @@ public class FileHandler extends StreamHandler {
* Constructs a new {@code FileHandler}. The given name pattern is used as
* output filename, the file limit is set to zero (no limit), the file count
* is set to one; the remaining configuration is done using
- * {@code LogManager} properties or their default values. This handler write
- * to only one file without size limit.
- *
+ * {@code LogManager} properties or their default values. This handler
+ * writes to only one file with no size limit.
+ *
* @param pattern
* the name pattern for the output file.
* @throws IOException
@@ -413,7 +407,6 @@ public class FileHandler extends StreamHandler {
* if the pattern is empty.
* @throws NullPointerException
* if the pattern is {@code null}.
- * @since Android 1.0
*/
public FileHandler(String pattern) throws IOException {
if (pattern.equals("")) { //$NON-NLS-1$
@@ -429,9 +422,9 @@ public class FileHandler extends StreamHandler {
* output filename, the file limit is set to zero (no limit), the file count
* is initialized to one and the value of {@code append} becomes the new
* instance's append mode. The remaining configuration is done using
- * {@code LogManager} properties. This handler write to only one file
- * without size limit.
- *
+ * {@code LogManager} properties. This handler writes to only one file
+ * with no size limit.
+ *
* @param pattern
* the name pattern for the output file.
* @param append
@@ -448,11 +441,10 @@ public class FileHandler extends StreamHandler {
* if {@code pattern} is empty.
* @throws NullPointerException
* if {@code pattern} is {@code null}.
- * @since Android 1.0
*/
public FileHandler(String pattern, boolean append) throws IOException {
if (pattern.equals("")) { //$NON-NLS-1$
- throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$
}
init(pattern, Boolean.valueOf(append), Integer.valueOf(DEFAULT_LIMIT),
@@ -466,7 +458,7 @@ public class FileHandler extends StreamHandler {
* is done using {@code LogManager} properties. This handler is configured
* to write to a rotating set of count files, when the limit of bytes has
* been written to one output file, another file will be opened instead.
- *
+ *
* @param pattern
* the name pattern for the output file.
* @param limit
@@ -487,11 +479,10 @@ public class FileHandler extends StreamHandler {
* {@code count < 1}.
* @throws NullPointerException
* if {@code pattern} is {@code null}.
- * @since Android 1.0
*/
public FileHandler(String pattern, int limit, int count) throws IOException {
if (pattern.equals("")) { //$NON-NLS-1$
- throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$
}
if (limit < 0 || count < 1) {
// logging.1B=The limit and count property must be larger than 0 and
@@ -509,7 +500,7 @@ public class FileHandler extends StreamHandler {
* {@code LogManager} properties. This handler is configured to write to a
* rotating set of count files, when the limit of bytes has been written to
* one output file, another file will be opened instead.
- *
+ *
* @param pattern
* the name pattern for the output file.
* @param limit
@@ -532,12 +523,11 @@ public class FileHandler extends StreamHandler {
* {@code count < 1}.
* @throws NullPointerException
* if {@code pattern} is {@code null}.
- * @since Android 1.0
*/
public FileHandler(String pattern, int limit, int count, boolean append)
throws IOException {
if (pattern.equals("")) { //$NON-NLS-1$
- throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$
}
if (limit < 0 || count < 1) {
// logging.1B=The limit and count property must be larger than 0 and
@@ -550,14 +540,13 @@ public class FileHandler extends StreamHandler {
/**
* Flushes and closes all opened files.
- *
+ *
* @throws SecurityException
* if a security manager exists and it determines that the
* caller does not have the required permissions to control this
* handler; required permissions include
* {@code LogPermission("control")},
* {@code FilePermission("write")} etc.
- * @since Android 1.0
*/
@Override
public void close() {
@@ -577,10 +566,9 @@ public class FileHandler extends StreamHandler {
/**
* Publish a {@code LogRecord}.
- *
+ *
* @param record
* the log record to publish.
- * @since Android 1.0
*/
@Override
public void publish(LogRecord record) {
diff --git a/logging/src/main/java/java/util/logging/Filter.java b/logging/src/main/java/java/util/logging/Filter.java
index e81f216..f5dbd9f 100644
--- a/logging/src/main/java/java/util/logging/Filter.java
+++ b/logging/src/main/java/java/util/logging/Filter.java
@@ -20,8 +20,6 @@ package java.util.logging;
/**
* A {@code Filter} provides a mechanism for exercising fine-grained control
* over which records get logged.
- *
- * @since Android 1.0
*/
public interface Filter {
@@ -32,7 +30,6 @@ public interface Filter {
* the {@link LogRecord} to be checked.
* @return {@code true} if the supplied log record needs to be logged,
* {@code false} otherwise.
- * @since Android 1.0
*/
boolean isLoggable(LogRecord record);
}
diff --git a/logging/src/main/java/java/util/logging/Formatter.java b/logging/src/main/java/java/util/logging/Formatter.java
index 2941c24..f9b0d25 100644
--- a/logging/src/main/java/java/util/logging/Formatter.java
+++ b/logging/src/main/java/java/util/logging/Formatter.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.text.MessageFormat;
@@ -26,41 +25,24 @@ import java.util.ResourceBundle;
* string representation. Head and tail strings are sometimes used to wrap a set
* of records. The {@code getHead} and {@code getTail} methods are used for this
* purpose.
- *
- * @since Android 1.0
*/
public abstract class Formatter {
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
-
/**
* Constructs a {@code Formatter} object.
- *
- * @since Android 1.0
*/
protected Formatter() {
super();
}
- /*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
-
/**
* Converts a {@link LogRecord} object into a string representation. The
* resulted string is usually localized and includes the message field of
* the record.
- *
+ *
* @param r
* the log record to be formatted into a string.
* @return the formatted string.
- * @since Android 1.0
*/
public abstract String format(LogRecord r);
@@ -71,16 +53,13 @@ public abstract class Formatter {
* <p>
* The message string is firstly localized using the {@code ResourceBundle}
* object associated with the supplied {@code LogRecord}.
- * </p>
* <p>
* Notice : if message contains "{0", then java.text.MessageFormat is used.
* Otherwise no formatting is performed.
- * </p>
- *
+ *
* @param r
* the log record to be formatted.
* @return the string resulted from the formatting.
- * @since Android 1.0
*/
public String formatMessage(LogRecord r) {
String pattern = r.getMessage();
@@ -114,14 +93,12 @@ public abstract class Formatter {
/**
* Gets the head string used to wrap a set of log records. This base class
* always returns an empty string.
- *
+ *
* @param h
* the target handler.
* @return the head string used to wrap a set of log records, empty in this
* implementation.
- * @since Android 1.0
*/
- @SuppressWarnings("unused")
public String getHead(Handler h) {
return ""; //$NON-NLS-1$
}
@@ -129,17 +106,13 @@ public abstract class Formatter {
/**
* Gets the tail string used to wrap a set of log records. This base class
* always returns the empty string.
- *
+ *
* @param h
* the target handler.
* @return the tail string used to wrap a set of log records, empty in this
* implementation.
- * @since Android 1.0
*/
- @SuppressWarnings("unused")
public String getTail(Handler h) {
return ""; //$NON-NLS-1$
}
-
}
-
diff --git a/logging/src/main/java/java/util/logging/Handler.java b/logging/src/main/java/java/util/logging/Handler.java
index d28bce0..a5b92a0 100644
--- a/logging/src/main/java/java/util/logging/Handler.java
+++ b/logging/src/main/java/java/util/logging/Handler.java
@@ -15,13 +15,12 @@
* limitations under the License.
*/
-
package java.util.logging;
+import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
-import java.io.UnsupportedEncodingException;
import org.apache.harmony.logging.internal.nls.Messages;
@@ -29,24 +28,11 @@ import org.apache.harmony.logging.internal.nls.Messages;
* A {@code Handler} object accepts a logging request and exports the desired
* messages to a target, for example, a file, the console, etc. It can be
* disabled by setting its logging level to {@code Level.OFF}.
- *
- * @since Android 1.0
*/
public abstract class Handler {
- /*
- * -------------------------------------------------------------------
- * Constants
- * -------------------------------------------------------------------
- */
private static final Level DEFAULT_LEVEL = Level.ALL;
- /*
- * -------------------------------------------------------------------
- * Instance variables
- * -------------------------------------------------------------------
- */
-
// the error manager to report errors during logging
private ErrorManager errorMan;
@@ -65,18 +51,10 @@ public abstract class Handler {
// class name, used for property reading
private String prefix;
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
-
/**
* Constructs a {@code Handler} object with a default error manager instance
* {@code ErrorManager}, the default encoding, and the default logging
* level {@code Level.ALL}. It has no filter and no formatter.
- *
- * @since Android 1.0
*/
protected Handler() {
this.errorMan = new ErrorManager();
@@ -87,12 +65,6 @@ public abstract class Handler {
this.prefix = this.getClass().getName();
}
- /*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
-
// get a instance from given class name, using Class.forName()
private Object getDefaultInstance(String className) {
Object result = null;
@@ -102,7 +74,7 @@ public abstract class Handler {
try {
result = Class.forName(className).newInstance();
} catch (Exception e) {
- //ignore
+ // ignore
}
return result;
}
@@ -110,7 +82,8 @@ public abstract class Handler {
// get a instance from given class name, using context classloader
private Object getCustomizeInstance(final String className)
throws Exception {
- Class<?> c = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ Class<?> c = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws Exception {
ClassLoader loader = Thread.currentThread()
.getContextClassLoader();
@@ -126,22 +99,22 @@ public abstract class Handler {
// print error message in some format
void printInvalidPropMessage(String key, String value, Exception e) {
// logging.12=Invalid property value for
- String msg = new StringBuilder().append(Messages.getString("logging.12")) //$NON-NLS-1$
+ String msg = new StringBuilder().append(
+ Messages.getString("logging.12")) //$NON-NLS-1$
.append(prefix).append(":").append(key).append("/").append( //$NON-NLS-1$//$NON-NLS-2$
value).toString();
errorMan.error(msg, e, ErrorManager.GENERIC_FAILURE);
}
- /*
+ /**
* init the common properties, including filter, level, formatter, and
* encoding
*/
- @SuppressWarnings("unused")
void initProperties(String defaultLevel, String defaultFilter,
String defaultFormatter, String defaultEncoding) {
LogManager manager = LogManager.getLogManager();
- //set filter
+ // set filter
final String filterName = manager.getProperty(prefix + ".filter"); //$NON-NLS-1$
if (null != filterName) {
try {
@@ -154,7 +127,7 @@ public abstract class Handler {
filter = (Filter) getDefaultInstance(defaultFilter);
}
- //set level
+ // set level
String levelName = manager.getProperty(prefix + ".level"); //$NON-NLS-1$
if (null != levelName) {
try {
@@ -167,7 +140,7 @@ public abstract class Handler {
level = Level.parse(defaultLevel);
}
- //set formatter
+ // set formatter
final String formatterName = manager.getProperty(prefix + ".formatter"); //$NON-NLS-1$
if (null != formatterName) {
try {
@@ -180,7 +153,7 @@ public abstract class Handler {
formatter = (Formatter) getDefaultInstance(defaultFormatter);
}
- //set encoding
+ // set encoding
final String encodingName = manager.getProperty(prefix + ".encoding"); //$NON-NLS-1$
try {
internalSetEncoding(encodingName);
@@ -193,37 +166,31 @@ public abstract class Handler {
* Closes this handler. A flush operation will be performed and all the
* associated resources will be freed. Client applications should not use
* this handler after closing it.
- *
+ *
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- *
- * @since Android 1.0
*/
public abstract void close();
/**
* Flushes any buffered output.
- *
- * @since Android 1.0
*/
public abstract void flush();
/**
* Accepts a logging request and sends it to the the target.
- *
+ *
* @param record
* the log record to be logged; {@code null} records are ignored.
- * @since Android 1.0
*/
public abstract void publish(LogRecord record);
/**
* Gets the character encoding used by this handler, {@code null} for
* default encoding.
- *
+ *
* @return the character encoding used by this handler.
- * @since Android 1.0
*/
public String getEncoding() {
return this.encoding;
@@ -232,12 +199,11 @@ public abstract class Handler {
/**
* Gets the error manager used by this handler to report errors during
* logging.
- *
+ *
* @return the error manager used by this handler.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public ErrorManager getErrorManager() {
LogManager.getLogManager().checkAccess();
@@ -246,9 +212,8 @@ public abstract class Handler {
/**
* Gets the filter used by this handler.
- *
+ *
* @return the filter used by this handler (possibly {@code null}).
- * @since Android 1.0
*/
public Filter getFilter() {
return this.filter;
@@ -256,9 +221,8 @@ public abstract class Handler {
/**
* Gets the formatter used by this handler to format the logging messages.
- *
+ *
* @return the formatter used by this handler (possibly {@code null}).
- * @since Android 1.0
*/
public Formatter getFormatter() {
return this.formatter;
@@ -267,9 +231,8 @@ public abstract class Handler {
/**
* Gets the logging level of this handler, records with levels lower than
* this value will be dropped.
- *
+ *
* @return the logging level of this handler.
- * @since Android 1.0
*/
public Level getLevel() {
return this.level;
@@ -278,12 +241,11 @@ public abstract class Handler {
/**
* Determines whether the supplied log record needs to be logged. The
* logging levels will be checked as well as the filter.
- *
+ *
* @param record
* the log record to be checked.
* @return {@code true} if the supplied log record needs to be logged,
* otherwise {@code false}.
- * @since Android 1.0
*/
public boolean isLoggable(LogRecord record) {
if (null == record) {
@@ -302,14 +264,13 @@ public abstract class Handler {
* {@code ErrorManager} is used for that purpose. No security checks are
* done, therefore this is compatible with environments where the caller
* is non-privileged.
- *
+ *
* @param msg
* the error message, may be {@code null}.
* @param ex
* the associated exception, may be {@code null}.
* @param code
* an {@code ErrorManager} error code.
- * @since Android 1.0
*/
protected void reportError(String msg, Exception ex, int code) {
this.errorMan.error(msg, ex, code);
@@ -319,12 +280,11 @@ public abstract class Handler {
* Sets the character encoding used by this handler. A {@code null} value
* indicates the use of the default encoding. This internal method does
* not check security.
- *
+ *
* @param newEncoding
* the character encoding to set.
* @throws UnsupportedEncodingException
* if the specified encoding is not supported by the runtime.
- * @since Android 1.0
*/
void internalSetEncoding(String newEncoding)
throws UnsupportedEncodingException {
@@ -347,7 +307,7 @@ public abstract class Handler {
/**
* Sets the character encoding used by this handler, {@code null} indicates
* a default encoding.
- *
+ *
* @param encoding
* the character encoding to set.
* @throws SecurityException
@@ -355,7 +315,6 @@ public abstract class Handler {
* have the required permission.
* @throws UnsupportedEncodingException
* if the specified encoding is not supported by the runtime.
- * @since Android 1.0
*/
public void setEncoding(String encoding) throws SecurityException,
UnsupportedEncodingException {
@@ -365,7 +324,7 @@ public abstract class Handler {
/**
* Sets the error manager for this handler.
- *
+ *
* @param em
* the error manager to set.
* @throws NullPointerException
@@ -373,7 +332,6 @@ public abstract class Handler {
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setErrorManager(ErrorManager em) {
LogManager.getLogManager().checkAccess();
@@ -385,13 +343,12 @@ public abstract class Handler {
/**
* Sets the filter to be used by this handler.
- *
+ *
* @param newFilter
* the filter to set, may be {@code null}.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setFilter(Filter newFilter) {
LogManager.getLogManager().checkAccess();
@@ -401,7 +358,7 @@ public abstract class Handler {
/**
* Sets the formatter to be used by this handler. This internal method does
* not check security.
- *
+ *
* @param newFormatter
* the formatter to set.
*/
@@ -414,7 +371,7 @@ public abstract class Handler {
/**
* Sets the formatter to be used by this handler.
- *
+ *
* @param newFormatter
* the formatter to set.
* @throws NullPointerException
@@ -422,7 +379,6 @@ public abstract class Handler {
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setFormatter(Formatter newFormatter) {
LogManager.getLogManager().checkAccess();
@@ -432,7 +388,7 @@ public abstract class Handler {
/**
* Sets the logging level of the messages logged by this handler, levels
* lower than this value will be dropped.
- *
+ *
* @param newLevel
* the logging level to set.
* @throws NullPointerException
@@ -440,7 +396,6 @@ public abstract class Handler {
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setLevel(Level newLevel) {
if (null == newLevel) {
@@ -450,4 +405,3 @@ public abstract class Handler {
this.level = newLevel;
}
}
-
diff --git a/logging/src/main/java/java/util/logging/Level.java b/logging/src/main/java/java/util/logging/Level.java
index 32ba017..f988127 100644
--- a/logging/src/main/java/java/util/logging/Level.java
+++ b/logging/src/main/java/java/util/logging/Level.java
@@ -41,8 +41,6 @@ import dalvik.system.VMStack;
* INFO, WARNING, SEVERE. There are two additional predefined levels, which are
* ALL and OFF. ALL indicates logging all messages, and OFF indicates logging no
* messages.
- * </p>
- * @since Android 1.0
*/
public class Level implements Serializable {
@@ -52,70 +50,52 @@ public class Level implements Serializable {
/**
* The OFF level provides no logging messages.
- *
- * @since Android 1.0
*/
public static final Level OFF = new Level("OFF", Integer.MAX_VALUE); //$NON-NLS-1$
/**
* The SEVERE level provides severe failure messages.
- *
- * @since Android 1.0
*/
public static final Level SEVERE = new Level("SEVERE", 1000); //$NON-NLS-1$
/**
* The WARNING level provides warnings.
- *
- * @since Android 1.0
*/
public static final Level WARNING = new Level("WARNING", 900); //$NON-NLS-1$
/**
* The INFO level provides informative messages.
- *
- * @since Android 1.0
*/
public static final Level INFO = new Level("INFO", 800); //$NON-NLS-1$
/**
* The CONFIG level provides static configuration messages.
- *
- * @since Android 1.0
*/
public static final Level CONFIG = new Level("CONFIG", 700); //$NON-NLS-1$
/**
* The FINE level provides tracing messages.
- *
- * @since Android 1.0
*/
public static final Level FINE = new Level("FINE", 500); //$NON-NLS-1$
/**
* The FINER level provides more detailed tracing messages.
- *
- * @since Android 1.0
*/
public static final Level FINER = new Level("FINER", 400); //$NON-NLS-1$
/**
* The FINEST level provides highly detailed tracing messages.
- *
- * @since Android 1.0
*/
public static final Level FINEST = new Level("FINEST", 300); //$NON-NLS-1$
/**
* The ALL level provides all logging messages.
- *
- * @since Android 1.0
*/
public static final Level ALL = new Level("ALL", Integer.MIN_VALUE); //$NON-NLS-1$
/**
* Parses a level name into a {@code Level} object.
- *
+ *
* @param name
* the name of the desired {@code level}, which cannot be
* {@code null}.
@@ -124,13 +104,8 @@ public class Level implements Serializable {
* if {@code name} is {@code null}.
* @throws IllegalArgumentException
* if {@code name} is not valid.
- * @since Android 1.0
*/
public static Level parse(String name) throws IllegalArgumentException {
- // BEGIN android-note
- // final modifier removed and IAE added to get closer to the RI
- // copied from newer version of harmony
- // END android-note
if (name == null) {
// logging.1C=The 'name' parameter is null.
throw new NullPointerException(Messages.getString("logging.1C")); //$NON-NLS-1$
@@ -155,8 +130,8 @@ public class Level implements Serializable {
if (isNameAnInt) {
/*
- * Loop through levels a second time, so that the
- * returned instance will be passed on the order of construction.
+ * Loop through levels a second time, so that the returned
+ * instance will be passed on the order of construction.
*/
for (Level level : levels) {
if (nameAsInt == level.intValue()) {
@@ -168,7 +143,8 @@ public class Level implements Serializable {
if (!isNameAnInt) {
// logging.1D=Cannot parse this name: {0}
- throw new IllegalArgumentException(Messages.getString("logging.1D", name)); //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString(
+ "logging.1D", name)); //$NON-NLS-1$
}
return new Level(name, nameAsInt);
@@ -176,21 +152,21 @@ public class Level implements Serializable {
/**
* The name of this Level.
- *
+ *
* @serial
*/
private final String name;
/**
* The integer value indicating the level.
- *
+ *
* @serial
*/
private final int value;
/**
* The name of the resource bundle used to localize the level name.
- *
+ *
* @serial
*/
private final String resourceBundleName;
@@ -204,14 +180,13 @@ public class Level implements Serializable {
/**
* Constructs an instance of {@code Level} taking the supplied name and
* level value.
- *
+ *
* @param name
* the name of the level.
* @param level
* an integer value indicating the level.
* @throws NullPointerException
* if {@code name} is {@code null}.
- * @since Android 1.0
*/
protected Level(String name, int level) {
this(name, level, null);
@@ -220,7 +195,7 @@ public class Level implements Serializable {
/**
* Constructs an instance of {@code Level} taking the supplied name, level
* value and resource bundle name.
- *
+ *
* @param name
* the name of the level.
* @param level
@@ -229,7 +204,6 @@ public class Level implements Serializable {
* the name of the resource bundle to use.
* @throws NullPointerException
* if {@code name} is {@code null}.
- * @since Android 1.0
*/
protected Level(String name, int level, String resourceBundleName) {
if (name == null) {
@@ -256,9 +230,8 @@ public class Level implements Serializable {
/**
* Gets the name of this level.
- *
+ *
* @return this level's name.
- * @since Android 1.0
*/
public String getName() {
return this.name;
@@ -266,9 +239,8 @@ public class Level implements Serializable {
/**
* Gets the name of the resource bundle associated with this level.
- *
+ *
* @return the name of this level's resource bundle.
- * @since Android 1.0
*/
public String getResourceBundleName() {
return this.resourceBundleName;
@@ -276,20 +248,17 @@ public class Level implements Serializable {
/**
* Gets the integer value indicating this level.
- *
+ *
* @return this level's integer value.
- * @since Android 1.0
*/
public final int intValue() {
return this.value;
}
/**
- * <p>
* Serialization helper method to maintain singletons and add any new
* levels.
- * </p>
- *
+ *
* @return the resolved instance.
*/
private Object readResolve() {
@@ -298,7 +267,7 @@ public class Level implements Serializable {
if (value != level.value) {
continue;
}
- if (!name.equals(name)) {
+ if (!name.equals(level.name)) {
continue;
}
if (resourceBundleName == level.resourceBundleName) {
@@ -316,7 +285,7 @@ public class Level implements Serializable {
/**
* Serialization helper to setup transient resource bundle instance.
- *
+ *
* @param in
* the input stream to read the instance data from.
* @throws IOException
@@ -324,7 +293,8 @@ public class Level implements Serializable {
* @throws ClassNotFoundException
* if a class is not found.
*/
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ private void readObject(ObjectInputStream in) throws IOException,
+ ClassNotFoundException {
in.defaultReadObject();
if (resourceBundleName != null) {
try {
@@ -339,9 +309,8 @@ public class Level implements Serializable {
* Gets the localized name of this level. The default locale is used. If no
* resource bundle is associated with this level then the original level
* name is returned.
- *
+ *
* @return the localized name of this level.
- * @since Android 1.0
*/
public String getLocalizedName() {
if (rb == null) {
@@ -358,12 +327,11 @@ public class Level implements Serializable {
/**
* Compares two {@code Level} objects for equality. They are considered to
* be equal if they have the same level value.
- *
+ *
* @param o
* the other object to compare this level to.
* @return {@code true} if this object equals to the supplied object,
* {@code false} otherwise.
- * @since Android 1.0
*/
@Override
public boolean equals(Object o) {
@@ -380,9 +348,8 @@ public class Level implements Serializable {
/**
* Returns the hash code of this {@code Level} object.
- *
+ *
* @return this level's hash code.
- * @since Android 1.0
*/
@Override
public int hashCode() {
@@ -392,9 +359,8 @@ public class Level implements Serializable {
/**
* Returns the string representation of this {@code Level} object. In
* this case, it is the level's name.
- *
+ *
* @return the string representation of this level.
- * @since Android 1.0
*/
@Override
public final String toString() {
diff --git a/logging/src/main/java/java/util/logging/LogManager.java b/logging/src/main/java/java/util/logging/LogManager.java
index 8409b81..308daaf 100644
--- a/logging/src/main/java/java/util/logging/LogManager.java
+++ b/logging/src/main/java/java/util/logging/LogManager.java
@@ -24,6 +24,10 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+// BEGIN android-removed
+//import java.lang.management.ManagementFactory;
+//import java.lang.reflect.Method;
+// END android-removed
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
@@ -33,13 +37,11 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
+
// BEGIN android-removed
-// import java.lang.management.ManagementFactory;
-// import java.lang.reflect.Method;
-// import javax.management.MBeanServer;
-// import javax.management.ObjectName;
-// import javax.management.ObjectInstance;
-// import javax.management.MalformedObjectNameException;
+//import javax.management.MBeanServer;
+//import javax.management.ObjectInstance;
+//import javax.management.ObjectName;
// END android-removed
import org.apache.harmony.logging.internal.nls.Messages;
@@ -49,23 +51,19 @@ import org.apache.harmony.logging.internal.nls.Messages;
* logging framework, and to manage a hierarchical namespace of all named
* {@code Logger} objects.
* <p>
- *
* There is only one global {@code LogManager} instance in the
* application, which can be get by calling static method
* {@link #getLogManager()}. This instance is created and
* initialized during class initialization and cannot be changed.
- * </p>
* <p>
* The {@code LogManager} class can be specified by
* java.util.logging.manager system property, if the property is unavailable or
* invalid, the default class {@link java.util.logging.LogManager} will
* be used.
- * </p>
* <p>
- * When initialization, {@code LogManager} read its configuration from a
+ * On initialization, {@code LogManager} reads its configuration from a
* properties file, which by default is the "lib/logging.properties" in the JRE
* directory.
- * </p>
* <p>
* However, two optional system properties can be used to customize the initial
* configuration process of {@code LogManager}.
@@ -73,31 +71,26 @@ import org.apache.harmony.logging.internal.nls.Messages;
* <li>"java.util.logging.config.class"</li>
* <li>"java.util.logging.config.file"</li>
* </ul>
- * </p>
* <p>
* These two properties can be set in three ways, by the Preferences API, by the
* "java" command line property definitions, or by system property definitions
* passed to JNI_CreateJavaVM.
- * </p>
* <p>
* The "java.util.logging.config.class" should specifies a class name. If it is
* set, this given class will be loaded and instantiated during
* {@code LogManager} initialization, so that this object's default
* constructor can read the initial configuration and define properties for
* {@code LogManager}.
- * </p>
* <p>
* If "java.util.logging.config.class" property is not set, or it is invalid, or
* some exception is thrown during the instantiation, then the
* "java.util.logging.config.file" system property can be used to specify a
* properties file. The {@code LogManager} will read initial
* configuration from this file.
- * </p>
* <p>
* If neither of these properties is defined, or some exception is thrown
* during these two properties using, the {@code LogManager} will read
* its initial configuration from default properties file, as described above.
- * </p>
* <p>
* The global logging properties may include:
* <ul>
@@ -113,22 +106,18 @@ import org.apache.harmony.logging.internal.nls.Messages;
* some logger, etc. These classes will be loaded and instantiated during
* {@code LogManager} configuration</li>
* </ul>
- * </p>
* <p>
* This class, together with any handler and configuration classes associated
* with it, <b>must</b> be loaded from the system classpath when
* {@code LogManager} configuration occurs.
- * </p>
* <p>
* Besides global properties, the properties for loggers and Handlers can be
* specified in the property files. The names of these properties will start
* with the complete dot separated names for the handlers or loggers.
- * </p>
* <p>
* In the {@code LogManager}'s hierarchical namespace,
* {@code Loggers} are organized based on their dot separated names. For
* example, "x.y.z" is child of "x.y".
- * </p>
* <p>
* Levels for {@code Loggers} can be defined by properties whose name end
* with ".level". Thus "alogger.level" defines a level for the logger named as
@@ -136,23 +125,15 @@ import org.apache.harmony.logging.internal.nls.Messages;
* properties are read and applied in the same order as they are specified in
* the property file. The root logger's level can be defined by the property
* named as ".level".
- * </p>
* <p>
* All methods on this type can be taken as being thread safe.
- * </p>
- *
+ *
*/
public class LogManager {
- /*
- * -------------------------------------------------------------------
- * Class variables
- * -------------------------------------------------------------------
- */
// The line separator of the underlying OS
// Use privileged code to read the line.separator system property
- private static final String lineSeparator =
- getPrivilegedSystemProperty("line.separator"); //$NON-NLS-1$
+ private static final String lineSeparator = getPrivilegedSystemProperty("line.separator"); //$NON-NLS-1$
// The shared logging permission
private static final LoggingPermission perm = new LoggingPermission(
@@ -160,63 +141,55 @@ public class LogManager {
// the singleton instance
static LogManager manager;
-
+
/**
* The {@code String} value of the {@link LoggingMXBean}'s ObjectName.
- *
- * @since Android 1.0
*/
- public static final String LOGGING_MXBEAN_NAME =
- "java.util.logging:type=Logging"; //$NON-NLS-1$
+ public static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; //$NON-NLS-1$
/**
* Get the {@code LoggingMXBean} instance. this implementation always throws
* an UnsupportedOperationException.
- *
+ *
* @return the {@code LoggingMXBean} instance
*/
public static LoggingMXBean getLoggingMXBean() {
- // BEGIN android-added
- throw new UnsupportedOperationException();
- // END android-added
- // BEGIN android-removed
- // try {
- // ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME);
- // MBeanServer platformBeanServer =
- // ManagementFactory.getPlatformMBeanServer();
- // Set loggingMXBeanSet = platformBeanServer.queryMBeans(
- // loggingMXBeanName, null);
- //
- // if (loggingMXBeanSet.size() != 1) {
- // // logging.21=There Can Be Only One logging MX bean.
- // throw new AssertionError(Messages.getString("logging.21"));
- // }
- //
- // Iterator i = loggingMXBeanSet.iterator();
- // ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next();
- // String lmxbcn = loggingMXBeanOI.getClassName();
- // Class lmxbc = Class.forName(lmxbcn);
- // Method giMethod = lmxbc.getDeclaredMethod("getInstance");
- // giMethod.setAccessible(true);
- // LoggingMXBean lmxb = (LoggingMXBean)
- // giMethod.invoke(null, new Object[] {});
- //
- // return lmxb;
- // } catch (Exception e) {
- // //TODO
- // //e.printStackTrace();
- // }
- // // logging.22=Exception occurred while getting the logging MX bean.
- // throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$
- // END android-removed
- }
+ // BEGIN android-added
+ throw new UnsupportedOperationException();
+ // END android-added
+ // BEGIN android-removed
+ // try {
+ // ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME);
+ // MBeanServer platformBeanServer = ManagementFactory
+ // .getPlatformMBeanServer();
+ // Set<?> loggingMXBeanSet = platformBeanServer.queryMBeans(
+ // loggingMXBeanName, null);
+ //
+ // if (loggingMXBeanSet.size() != 1) {
+ // // logging.21=There Can Be Only One logging MX bean.
+ // throw new AssertionError(Messages.getString("logging.21")); //$NON-NLS-1$
+ // }
+ //
+ // Iterator<?> i = loggingMXBeanSet.iterator();
+ // ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next();
+ // String lmxbcn = loggingMXBeanOI.getClassName();
+ // Class<?> lmxbc = Class.forName(lmxbcn);
+ // Method giMethod = lmxbc.getDeclaredMethod("getInstance"); //$NON-NLS-1$
+ // giMethod.setAccessible(true);
+ // LoggingMXBean lmxb = (LoggingMXBean) giMethod.invoke(null,
+ // new Object[] {});
+ //
+ // return lmxb;
+ // } catch (Exception e) {
+ // // TODO
+ // // e.printStackTrace();
+ // }
+ // // logging.22=Exception occurred while getting the logging MX bean.
+ // throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$
+ // END android-removed
+ }
- /*
- * -------------------------------------------------------------------
- * Instance variables
- * -------------------------------------------------------------------
- */
- //FIXME: use weak reference to avoid heap memory leak
+ // FIXME: use weak reference to avoid heap memory leak
private Hashtable<String, Logger> loggers;
// the configuration properties
@@ -225,19 +198,13 @@ public class LogManager {
// the property change listener
private PropertyChangeSupport listeners;
- /*
- * -------------------------------------------------------------------
- * Global initialization
- * -------------------------------------------------------------------
- */
-
static {
// init LogManager singleton instance
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
- String className = System.getProperty(
- "java.util.logging.manager"); //$NON-NLS-1$
-
+ String className = System
+ .getProperty("java.util.logging.manager"); //$NON-NLS-1$
+
if (null != className) {
manager = (LogManager) getInstanceByClass(className);
}
@@ -256,7 +223,7 @@ public class LogManager {
Logger root = new Logger("", null); //$NON-NLS-1$
root.setLevel(Level.INFO);
Logger.global.setParent(root);
-
+
manager.addLogger(root);
manager.addLogger(Logger.global);
return null;
@@ -290,11 +257,6 @@ public class LogManager {
}
/*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
- /*
* Package private utilities Returns the line separator of the underlying
* OS.
*/
@@ -307,7 +269,7 @@ public class LogManager {
* that it is trusted to modify the configuration for logging framework. If
* the check passes, just return, otherwise {@code SecurityException}
* will be thrown.
- *
+ *
* @throws SecurityException
* if there is a security manager in operation and the invoker
* of this method does not have the required security permission
@@ -330,7 +292,7 @@ public class LogManager {
* unexpectedly garbage collected it is necessary for <i>applications</i>
* to maintain references to them.
* </p>
- *
+ *
* @param logger
* the logger to be added.
* @return true if the given logger is added into the namespace
@@ -347,7 +309,6 @@ public class LogManager {
return true;
}
-
private void addToFamilyTree(Logger logger, String name) {
Logger parent = null;
// find parent
@@ -359,8 +320,8 @@ public class LogManager {
if (parent != null) {
logger.internalSetParent(parent);
break;
- } else if (getProperty(parentName+".level") != null || //$NON-NLS-1$
- getProperty(parentName+".handlers") != null) { //$NON-NLS-1$
+ } else if (getProperty(parentName + ".level") != null || //$NON-NLS-1$
+ getProperty(parentName + ".handlers") != null) { //$NON-NLS-1$
parent = Logger.getLogger(parentName);
logger.internalSetParent(parent);
break;
@@ -371,16 +332,22 @@ public class LogManager {
}
// find children
- //TODO: performance can be improved here?
+ // TODO: performance can be improved here?
Collection<Logger> allLoggers = loggers.values();
- for (Logger child : allLoggers) {
+ for (final Logger child : allLoggers) {
Logger oldParent = child.getParent();
if (parent == oldParent
&& (name.length() == 0 || child.getName().startsWith(
name + '.'))) {
- child.setParent(logger);
+ final Logger thisLogger = logger;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ child.setParent(thisLogger);
+ return null;
+ }
+ });
if (null != oldParent) {
- //-- remove from old parent as the parent has been changed
+ // -- remove from old parent as the parent has been changed
oldParent.removeChild(child);
}
}
@@ -389,7 +356,7 @@ public class LogManager {
/**
* Get the logger with the given name.
- *
+ *
* @param name
* name of logger
* @return logger with given name, or {@code null} if nothing is found.
@@ -400,7 +367,7 @@ public class LogManager {
/**
* Get a {@code Enumeration} of all registered logger names.
- *
+ *
* @return enumeration of registered logger names
*/
public synchronized Enumeration<String> getLoggerNames() {
@@ -409,7 +376,7 @@ public class LogManager {
/**
* Get the global {@code LogManager} instance.
- *
+ *
* @return the global {@code LogManager} instance
*/
public static LogManager getLogManager() {
@@ -418,7 +385,7 @@ public class LogManager {
/**
* Get the value of property with given name.
- *
+ *
* @param name
* the name of property
* @return the value of property
@@ -433,7 +400,7 @@ public class LogManager {
* <p>
* Notice : No {@code PropertyChangeEvent} are fired.
* </p>
- *
+ *
* @throws IOException
* if any IO related problems happened.
* @throws SecurityException
@@ -443,19 +410,20 @@ public class LogManager {
public void readConfiguration() throws IOException {
checkAccess();
// check config class
- String configClassName = System.getProperty(
- "java.util.logging.config.class"); //$NON-NLS-1$
- if (null == configClassName || null == getInstanceByClass(configClassName)) {
- // if config class failed, check config file
- String configFile = System.getProperty(
- "java.util.logging.config.file"); //$NON-NLS-1$
+ String configClassName = System
+ .getProperty("java.util.logging.config.class"); //$NON-NLS-1$
+ if (null == configClassName
+ || null == getInstanceByClass(configClassName)) {
+ // if config class failed, check config file
+ String configFile = System
+ .getProperty("java.util.logging.config.file"); //$NON-NLS-1$
if (null == configFile) {
// if cannot find configFile, use default logging.properties
configFile = new StringBuilder().append(
System.getProperty("java.home")).append(File.separator) //$NON-NLS-1$
.append("lib").append(File.separator).append( //$NON-NLS-1$
- "logging.properties").toString(); //$NON-NLS-1$
+ "logging.properties").toString(); //$NON-NLS-1$
}
InputStream input = null;
@@ -463,7 +431,7 @@ public class LogManager {
// BEGIN android-removed
// input = new BufferedInputStream(new FileInputStream(configFile));
// END android-removed
-
+
// BEGIN android-added
try {
input = new BufferedInputStream(
@@ -504,13 +472,12 @@ public class LogManager {
return clazz.newInstance();
} catch (Exception e) {
try {
- Class<?> clazz = Thread.currentThread()
- .getContextClassLoader().loadClass(className);
+ Class<?> clazz = Thread.currentThread().getContextClassLoader()
+ .loadClass(className);
return clazz.newInstance();
} catch (Exception innerE) {
- //logging.20=Loading class "{0}" failed
- System.err.println(Messages.getString(
- "logging.20", className)); //$NON-NLS-1$
+ // logging.20=Loading class "{0}" failed
+ System.err.println(Messages.getString("logging.20", className)); //$NON-NLS-1$
System.err.println(innerE);
return null;
}
@@ -523,7 +490,7 @@ public class LogManager {
throws IOException {
reset();
props.load(ins);
-
+
// parse property "config" and apply setting
String configs = props.getProperty("config"); //$NON-NLS-1$
if (null != configs) {
@@ -533,27 +500,25 @@ public class LogManager {
getInstanceByClass(configerName);
}
}
-
+
// set levels for logger
Collection<Logger> allLoggers = loggers.values();
- for(Logger logger : allLoggers){
- String property = props.getProperty(
- logger.getName()+".level"); //$NON-NLS-1$
- if(null != property){
+ for (Logger logger : allLoggers) {
+ String property = props.getProperty(logger.getName() + ".level"); //$NON-NLS-1$
+ if (null != property) {
logger.setLevel(Level.parse(property));
}
}
listeners.firePropertyChange(null, null, null);
}
-
/**
* Re-initialize the properties and configuration from the given
* {@code InputStream}
* <p>
* Notice : No {@code PropertyChangeEvent} are fired.
* </p>
- *
+ *
* @param ins
* the input stream
* @throws IOException
@@ -574,7 +539,7 @@ public class LogManager {
* level is set to null, except the root logger's level is set to
* {@code Level.INFO}.
* </p>
- *
+ *
* @throws SecurityException
* if security manager exists and it determines that caller does
* not have the required permissions to perform this action.
@@ -583,10 +548,10 @@ public class LogManager {
checkAccess();
props = new Properties();
Enumeration<String> names = getLoggerNames();
- while(names.hasMoreElements()){
+ while (names.hasMoreElements()) {
String name = names.nextElement();
Logger logger = getLogger(name);
- if(logger != null){
+ if (logger != null) {
logger.reset();
}
}
@@ -599,7 +564,7 @@ public class LogManager {
/**
* Add a {@code PropertyChangeListener}, which will be invoked when
* the properties are reread.
- *
+ *
* @param l
* the {@code PropertyChangeListener} to be added.
* @throws SecurityException
@@ -607,7 +572,7 @@ public class LogManager {
* not have the required permissions to perform this action.
*/
public void addPropertyChangeListener(PropertyChangeListener l) {
- if(l == null){
+ if (l == null) {
throw new NullPointerException();
}
checkAccess();
@@ -617,7 +582,7 @@ public class LogManager {
/**
* Remove a {@code PropertyChangeListener}, do nothing if the given
* listener is not found.
- *
+ *
* @param l
* the {@code PropertyChangeListener} to be removed.
* @throws SecurityException
diff --git a/logging/src/main/java/java/util/logging/LogRecord.java b/logging/src/main/java/java/util/logging/LogRecord.java
index b8a98ef..0a8e257 100644
--- a/logging/src/main/java/java/util/logging/LogRecord.java
+++ b/logging/src/main/java/java/util/logging/LogRecord.java
@@ -40,9 +40,6 @@ import org.apache.harmony.logging.internal.nls.Messages;
* {@code getSourceClassName} or {@code getSourceMethodName} if they expect to
* use them after passing the {@code LogRecord} object to another thread or
* transmitting it over RMI.
- * </p>
- *
- * @since Android 1.0
*/
public class LogRecord implements Serializable {
@@ -65,70 +62,70 @@ public class LogRecord implements Serializable {
/**
* The logging level.
- *
+ *
* @serial
*/
private Level level;
/**
* The sequence number.
- *
+ *
* @serial
*/
private long sequenceNumber;
/**
* The name of the class that issued the logging call.
- *
+ *
* @serial
*/
private String sourceClassName;
/**
* The name of the method that issued the logging call.
- *
+ *
* @serial
*/
private String sourceMethodName;
/**
* The original message text.
- *
+ *
* @serial
*/
private String message;
/**
* The ID of the thread that issued the logging call.
- *
+ *
* @serial
*/
private int threadID;
/**
* The time that the event occurred, in milliseconds since 1970.
- *
+ *
* @serial
*/
private long millis;
/**
* The associated {@code Throwable} object if any.
- *
+ *
* @serial
*/
private Throwable thrown;
/**
* The name of the source logger.
- *
+ *
* @serial
*/
private String loggerName;
/**
* The name of the resource bundle used to localize the log message.
- *
+ *
* @serial
*/
private String resourceBundleName;
@@ -148,14 +145,13 @@ public class LogRecord implements Serializable {
* sequence property is set to a new unique value, allocated in increasing
* order within the virtual machine. The thread ID is set to a unique value
* for the current thread. All other properties are set to {@code null}.
- *
+ *
* @param level
* the logging level, may not be {@code null}.
* @param msg
* the raw message.
* @throws NullPointerException
* if {@code level} is {@code null}.
- * @since Android 1.0
*/
public LogRecord(Level level, String msg) {
if (null == level) {
@@ -188,9 +184,8 @@ public class LogRecord implements Serializable {
/**
* Gets the logging level.
- *
+ *
* @return the logging level.
- * @since Android 1.0
*/
public Level getLevel() {
return level;
@@ -198,12 +193,11 @@ public class LogRecord implements Serializable {
/**
* Sets the logging level.
- *
+ *
* @param level
* the level to set.
* @throws NullPointerException
* if {@code level} is {@code null}.
- * @since Android 1.0
*/
public void setLevel(Level level) {
if (null == level) {
@@ -215,9 +209,8 @@ public class LogRecord implements Serializable {
/**
* Gets the name of the logger.
- *
+ *
* @return the logger name.
- * @since Android 1.0
*/
public String getLoggerName() {
return loggerName;
@@ -225,10 +218,9 @@ public class LogRecord implements Serializable {
/**
* Sets the name of the logger.
- *
+ *
* @param loggerName
* the logger name to set.
- * @since Android 1.0
*/
public void setLoggerName(String loggerName) {
this.loggerName = loggerName;
@@ -236,9 +228,8 @@ public class LogRecord implements Serializable {
/**
* Gets the raw message.
- *
+ *
* @return the raw message, may be {@code null}.
- * @since Android 1.0
*/
public String getMessage() {
return message;
@@ -248,10 +239,9 @@ public class LogRecord implements Serializable {
* Sets the raw message. When this record is formatted by a logger that has
* a localization resource bundle that contains an entry for {@code message},
* then the raw message is replaced with its localized version.
- *
+ *
* @param message
* the raw message to set, may be {@code null}.
- * @since Android 1.0
*/
public void setMessage(String message) {
this.message = message;
@@ -259,9 +249,8 @@ public class LogRecord implements Serializable {
/**
* Gets the time when this event occurred, in milliseconds since 1970.
- *
+ *
* @return the time when this event occurred, in milliseconds since 1970.
- * @since Android 1.0
*/
public long getMillis() {
return millis;
@@ -269,10 +258,9 @@ public class LogRecord implements Serializable {
/**
* Sets the time when this event occurred, in milliseconds since 1970.
- *
+ *
* @param millis
* the time when this event occurred, in milliseconds since 1970.
- * @since Android 1.0
*/
public void setMillis(long millis) {
this.millis = millis;
@@ -280,10 +268,9 @@ public class LogRecord implements Serializable {
/**
* Gets the parameters.
- *
+ *
* @return the array of parameters or {@code null} if there are no
* parameters.
- * @since Android 1.0
*/
public Object[] getParameters() {
return parameters;
@@ -291,10 +278,9 @@ public class LogRecord implements Serializable {
/**
* Sets the parameters.
- *
+ *
* @param parameters
* the array of parameters to set, may be {@code null}.
- * @since Android 1.0
*/
public void setParameters(Object[] parameters) {
this.parameters = parameters;
@@ -303,21 +289,20 @@ public class LogRecord implements Serializable {
/**
* Gets the resource bundle used to localize the raw message during
* formatting.
- *
+ *
* @return the associated resource bundle, {@code null} if none is
* available or the message is not localizable.
- * @since Android 1.0
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
/**
- * Sets the resource bundle.
- *
+ * Sets the resource bundle used to localize the raw message during
+ * formatting.
+ *
* @param resourceBundle
* the resource bundle to set, may be {@code null}.
- * @since Android 1.0
*/
public void setResourceBundle(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
@@ -325,10 +310,9 @@ public class LogRecord implements Serializable {
/**
* Gets the name of the resource bundle.
- *
+ *
* @return the name of the resource bundle, {@code null} if none is
* available or the message is not localizable.
- * @since Android 1.0
*/
public String getResourceBundleName() {
return resourceBundleName;
@@ -336,10 +320,9 @@ public class LogRecord implements Serializable {
/**
* Sets the name of the resource bundle.
- *
+ *
* @param resourceBundleName
* the name of the resource bundle to set.
- * @since Android 1.0
*/
public void setResourceBundleName(String resourceBundleName) {
this.resourceBundleName = resourceBundleName;
@@ -347,9 +330,8 @@ public class LogRecord implements Serializable {
/**
* Gets the sequence number.
- *
+ *
* @return the sequence number.
- * @since Android 1.0
*/
public long getSequenceNumber() {
return sequenceNumber;
@@ -359,10 +341,9 @@ public class LogRecord implements Serializable {
* Sets the sequence number. It is usually not necessary to call this method
* to change the sequence number because the number is allocated when this
* instance is constructed.
- *
+ *
* @param sequenceNumber
* the sequence number to set.
- * @since Android 1.0
*/
public void setSequenceNumber(long sequenceNumber) {
this.sequenceNumber = sequenceNumber;
@@ -371,9 +352,8 @@ public class LogRecord implements Serializable {
/**
* Gets the name of the class that is the source of this log record. This
* information can be changed, may be {@code null} and is untrusted.
- *
+ *
* @return the name of the source class of this log record (possiblity {@code null})
- * @since Android 1.0
*/
public String getSourceClassName() {
initSource();
@@ -394,7 +374,8 @@ public class LogRecord implements Serializable {
break FINDLOG;
}
}
- while(++i<elements.length && elements[i].getClassName().equals(current)) {
+ while (++i < elements.length
+ && elements[i].getClassName().equals(current)) {
// do nothing
}
if (i < elements.length) {
@@ -407,11 +388,10 @@ public class LogRecord implements Serializable {
/**
* Sets the name of the class that is the source of this log record.
- *
+ *
* @param sourceClassName
* the name of the source class of this log record, may be
* {@code null}.
- * @since Android 1.0
*/
public void setSourceClassName(String sourceClassName) {
sourceInited = true;
@@ -420,9 +400,8 @@ public class LogRecord implements Serializable {
/**
* Gets the name of the method that is the source of this log record.
- *
+ *
* @return the name of the source method of this log record.
- * @since Android 1.0
*/
public String getSourceMethodName() {
initSource();
@@ -431,11 +410,10 @@ public class LogRecord implements Serializable {
/**
* Sets the name of the method that is the source of this log record.
- *
+ *
* @param sourceMethodName
* the name of the source method of this log record, may be
* {@code null}.
- * @since Android 1.0
*/
public void setSourceMethodName(String sourceMethodName) {
sourceInited = true;
@@ -448,9 +426,8 @@ public class LogRecord implements Serializable {
* <p>
* Notice : the ID doesn't necessary map the OS thread ID
* </p>
- *
+ *
* @return the ID of the thread originating this log record.
- * @since Android 1.0
*/
public int getThreadID() {
return threadID;
@@ -458,10 +435,9 @@ public class LogRecord implements Serializable {
/**
* Sets the ID of the thread originating this log record.
- *
+ *
* @param threadID
* the new ID of the thread originating this log record.
- * @since Android 1.0
*/
public void setThreadID(int threadID) {
this.threadID = threadID;
@@ -469,9 +445,8 @@ public class LogRecord implements Serializable {
/**
* Gets the {@code Throwable} object associated with this log record.
- *
+ *
* @return the {@code Throwable} object associated with this log record.
- * @since Android 1.0
*/
public Throwable getThrown() {
return thrown;
@@ -479,11 +454,10 @@ public class LogRecord implements Serializable {
/**
* Sets the {@code Throwable} object associated with this log record.
- *
+ *
* @param thrown
* the new {@code Throwable} object to associate with this log
* record.
- * @since Android 1.0
*/
public void setThrown(Throwable thrown) {
this.thrown = thrown;
@@ -514,12 +488,13 @@ public class LogRecord implements Serializable {
in.defaultReadObject();
byte major = in.readByte();
byte minor = in.readByte();
- //only check MAJOR version
+ // only check MAJOR version
if (major != MAJOR) {
// logging.5=Different version - {0}.{1}
- throw new IOException(Messages.getString("logging.5", major, minor)); //$NON-NLS-1$
+ throw new IOException(Messages.getString("logging.5", //$NON-NLS-1$
+ Byte.valueOf(major), Byte.valueOf(minor)));
}
-
+
int length = in.readInt();
if (length >= 0) {
parameters = new Object[length];
diff --git a/logging/src/main/java/java/util/logging/Logger.java b/logging/src/main/java/java/util/logging/Logger.java
index cd88ca0..fe124d3 100644
--- a/logging/src/main/java/java/util/logging/Logger.java
+++ b/logging/src/main/java/java/util/logging/Logger.java
@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import java.util.StringTokenizer;
import org.apache.harmony.logging.internal.nls.Messages;
@@ -39,7 +38,6 @@ import org.apache.harmony.logging.internal.nls.Messages;
* namespace hierarchy managed by a log manager. The naming convention is
* usually the same as java package's naming convention, that is using
* dot-separated strings. Anonymous loggers do not belong to any namespace.
- * </p>
* <p>
* Loggers "inherit" log level setting from their parent if their own level is
* set to {@code null}. This is also true for the resource bundle. The logger's
@@ -49,36 +47,28 @@ import org.apache.harmony.logging.internal.nls.Messages;
* context, "inherit" only means that "behavior" is inherited. The internal
* field values will not change, for example, {@code getLevel()} still returns
* {@code null}.
- * </p>
* <p>
* When loading a given resource bundle, the logger first tries to use the
* context classloader. If that fails, it tries the system classloader. And if
* that still fails, it searches up the class stack and uses each class's
* classloader to try to locate the resource bundle.
- * </p>
* <p>
* Some log methods accept log requests that do not specify the source class and
* source method. In these cases, the logging framework will automatically infer
* the calling class and method, but this is not guaranteed to be accurate.
- * </p>
* <p>
* Once a {@code LogRecord} object has been passed into the logging framework,
* it is owned by the logging framework and the client applications should not
* use it any longer.
- * </p>
* <p>
* All methods of this class are thread-safe.
- * </p>
- *
+ *
* @see LogManager
- * @since Android 1.0
*/
public class Logger {
/**
* The global logger is provided as convenience for casual use.
- *
- * @since Android 1.0
*/
public final static Logger global = new Logger("global", null); //$NON-NLS-1$
@@ -116,27 +106,19 @@ public class Logger {
private boolean isNamed;
private List<Logger> childs;
-
+
private LogManager manager;
// BEGIN android-changed
private volatile boolean handlerInited;
// END android-changed
-
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
-
/**
* Constructs a {@code Logger} object with the supplied name and resource
* bundle name; {@code notifiyParentHandlers} is set to {@code true}.
* <p>
- * Notice : Loggers use a naming hierarchy. Thus "z.x.y" is a child of "z.x".
- * </p>
- *
+ * Notice : Loggers use a naming hierarchy. Thus "z.x.y" is a child of "z.x".
+ *
* @param name
* the name of this logger, may be {@code null} for anonymous
* loggers.
@@ -145,7 +127,6 @@ public class Logger {
* messages, may be {@code null}.
* @throws MissingResourceException
* if the specified resource bundle can not be loaded.
- * @since Android 1.0
*/
protected Logger(String name, String resourceBundleName) {
// try to load the specified resource bundle first
@@ -164,24 +145,24 @@ public class Logger {
// any logger is not anonymous by default
this.isNamed = true;
- //-- 'null' means that level will be inherited from parent (see getLevel)
- //-- Level.INFO is default level if we don't set it. It will be
- //-- changed to parent level or to configLevel after adding to the
- //-- family tree. As of this, actually, setting to Level.INFO is
- //-- not needed here.
+ // -- 'null' means that level will be inherited from parent (see
+ // getLevel)
+ // -- Level.INFO is default level if we don't set it. It will be
+ // -- changed to parent level or to configLevel after adding to the
+ // -- family tree. As of this, actually, setting to Level.INFO is
+ // -- not needed here.
this.levelObjVal = null;
this.levelIntVal = Level.INFO.intValue();
}
- //-- should be called under the lm lock
+ // -- should be called under the lm lock
private void setLevelImpl(Level newLevel) {
// update levels for the whole hierarchy
int oldVal = levelIntVal;
levelObjVal = newLevel;
if (null == newLevel) {
- levelIntVal = null != parent
- ? parent.levelIntVal
- : Level.INFO.intValue();
+ levelIntVal = null != parent ? parent.levelIntVal : Level.INFO
+ .intValue();
} else {
levelIntVal = newLevel.intValue();
}
@@ -190,7 +171,7 @@ public class Logger {
}
}
- //-- should be called under the lm lock
+ // -- should be called under the lm lock
private void forceChildsToInherit() {
for (Logger child : childs) {
if (null == child.levelObjVal) { // should inherit
@@ -199,15 +180,9 @@ public class Logger {
}
}
- /*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
-
/**
* Load the specified resource bundle, use privileged code.
- *
+ *
* @param resourceBundleName
* the name of the resource bundle to load, cannot be {@code null}.
* @return the loaded resource bundle.
@@ -216,8 +191,8 @@ public class Logger {
*/
static ResourceBundle loadResourceBundle(String resourceBundleName) {
// try context class loader to load the resource
- ClassLoader cl = AccessController.doPrivileged(
- new PrivilegedAction<ClassLoader>() {
+ ClassLoader cl = AccessController
+ .doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
@@ -231,12 +206,11 @@ public class Logger {
}
}
// try system class loader to load the resource
- cl = AccessController.doPrivileged(
- new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return ClassLoader.getSystemClassLoader();
- }
- });
+ cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return ClassLoader.getSystemClassLoader();
+ }
+ });
if (null != cl) {
try {
return ResourceBundle.getBundle(resourceBundleName, Locale
@@ -257,8 +231,8 @@ public class Logger {
for (int i = 1; i < classes.length; i++) {
final int index = i;
try {
- cl = AccessController.doPrivileged(
- new PrivilegedAction<ClassLoader>() {
+ cl = AccessController
+ .doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return classes[index].getClassLoader();
}
@@ -274,7 +248,7 @@ public class Logger {
}
// logging.8=Failed to load the specified resource bundle "{0}".
throw new MissingResourceException(Messages.getString("logging.8", //$NON-NLS-1$
- resourceBundleName), resourceBundleName, null);
+ resourceBundleName), resourceBundleName, null);
}
/**
@@ -284,10 +258,8 @@ public class Logger {
* <p>
* The anonymous loggers' parent is set to be the root logger. This way it
* inherits the default logging level and handlers from the root logger.
- * </p>
- *
+ *
* @return a new instance of anonymous logger.
- * @since Android 1.0
*/
public static Logger getAnonymousLogger() {
return getAnonymousLogger(null);
@@ -300,14 +272,12 @@ public class Logger {
* <p>
* The anonymous loggers' parent is set to be the root logger. This way it
* inherits default logging level and handlers from the root logger.
- * </p>
- *
+ *
* @param resourceBundleName
* the name of the resource bundle used to localize log messages.
* @return a new instance of anonymous logger.
* @throws MissingResourceException
* if the specified resource bundle can not be loaded.
- * @since Android 1.0
*/
public static Logger getAnonymousLogger(String resourceBundleName) {
final Logger l = new Logger(null, resourceBundleName);
@@ -324,26 +294,24 @@ public class Logger {
private static void updateResourceBundle(Logger l, String resourceBundleName) {
synchronized (l) {
if (null == l.getResourceBundleName()) {
- if(null == resourceBundleName){
+ if (null == resourceBundleName) {
return;
}
/*
- * load the resource bundle if none is specified
- * before
+ * load the resource bundle if none is specified before
*/
l.resBundle = loadResourceBundle(resourceBundleName);
l.resBundleName = resourceBundleName;
} else if (!l.getResourceBundleName().equals(resourceBundleName)) {
/*
- * throw exception if the specified resource bundles
- * are inconsistent with each other, i.e., different
- * names
+ * throw exception if the specified resource bundles are
+ * inconsistent with each other, i.e., different names
*/
- // logging.9=The specified resource bundle name "{0}" is
+ // logging.9=The specified resource bundle name "{0}" is
// inconsistent with the existing one "{1}".
throw new IllegalArgumentException(Messages.getString(
"logging.9", //$NON-NLS-1$
- resourceBundleName, l.getResourceBundleName()));
+ resourceBundleName, l.getResourceBundleName()));
}
}
}
@@ -378,11 +346,12 @@ public class Logger {
* Gets a named logger. The returned logger may already exist or may be
* newly created. In the latter case, its level will be set to the
* configured level according to the {@code LogManager}'s properties.
- *
+ *
* @param name
* the name of the logger to get, cannot be {@code null}.
* @return a named logger.
- * @since Android 1.0
+ * @throws MissingResourceException
+ * If the specified resource bundle can not be loaded.
*/
public static Logger getLogger(String name) {
return getLoggerWithRes(name, null, false);
@@ -391,7 +360,7 @@ public class Logger {
/**
* Gets a named logger associated with the supplied resource bundle. The
* resource bundle will be used to localize logging messages.
- *
+ *
* @param name
* the name of the logger to get, cannot be {@code null}.
* @param resourceBundleName
@@ -403,7 +372,6 @@ public class Logger {
* @throws MissingResourceException
* if the name of the resource bundle cannot be found.
* @return a named logger.
- * @since Android 1.0
*/
public static Logger getLogger(String name, String resourceBundleName) {
return getLoggerWithRes(name, resourceBundleName, true);
@@ -412,13 +380,12 @@ public class Logger {
/**
* Adds a handler to this logger. The {@code name} will be fed with log
* records received by this logger.
- *
+ *
* @param handler
* the handler object to add, cannot be {@code null}.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void addHandler(Handler handler) {
if (null == handler) {
@@ -430,25 +397,25 @@ public class Logger {
LogManager.getLogManager().checkAccess();
}
initHandler();
- synchronized(this){
+ synchronized (this) {
this.handlers.add(handler);
}
}
-
+
/*
- * Be cautious to avoid deadlock when using this method, it gets lock on manager
- * at first, and then gets lock on this Logger, so any methods should not hold
- * lock on this Logger when invoking this method.
+ * Be cautious to avoid deadlock when using this method, it gets lock on manager
+ * at first, and then gets lock on this Logger, so any methods should not hold
+ * lock on this Logger when invoking this method.
*/
private void initHandler() {
- if(!handlerInited){
+ if (!handlerInited) {
synchronized (this) {
if (!handlerInited) {
// BEGIN android-added
/*
* Force LogManager to be initialized, since its
* class init code performs necessary one-time setup.
- */
+ */
LogManager.getLogManager();
// END android-added
if (handlers == null) {
@@ -463,26 +430,27 @@ public class Logger {
if (null == handlerStr) {
return;
}
- StringTokenizer st = new StringTokenizer(handlerStr, " "); //$NON-NLS-1$
- while (st.hasMoreTokens()) {
- String handlerName = st.nextToken();
- // BEGIN android-changed
- // deal with non-existing handler
- try {
- Handler handler = (Handler) LogManager
- .getInstanceByClass(handlerName);
- handlers.add(handler);
- String level = manager.getProperty(handlerName
- + ".level"); //$NON-NLS-1$
- if (null != level) {
- handler.setLevel(Level.parse(level));
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- // END android-changed
+ String[] strs = handlerStr.split(",|\\s"); //$NON-NLS-1$
+ for (int i = 0; i < strs.length; i++) {
+ String handlerName = strs[i];
+ if (handlerName.equals("")) { //$NON-NLS-1$
+ continue;
+ }
+ // BEGIN android-changed
+ // deal with non-existing handler
+ try {
+ Handler handler = (Handler) LogManager.getInstanceByClass(handlerName);
+ handlers.add(handler);
+ String level = manager.getProperty(handlerName + ".level"); //$NON-NLS-1$
+ if (null != level) {
+ handler.setLevel(Level.parse(level));
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- handlerInited = true;
+ // END android-changed
+ }
+ handlerInited = true;
}
}
}
@@ -490,13 +458,12 @@ public class Logger {
/**
* Gets all the handlers associated with this logger.
- *
+ *
* @return an array of all the handlers associated with this logger.
- * @since Android 1.0
*/
public Handler[] getHandlers() {
initHandler();
- synchronized(this){
+ synchronized (this) {
return handlers.toArray(new Handler[handlers.size()]);
}
}
@@ -504,13 +471,12 @@ public class Logger {
/**
* Removes a handler from this logger. If the specified handler does not
* exist then this method has no effect.
- *
+ *
* @param handler
* the handler to be removed.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void removeHandler(Handler handler) {
// Anonymous loggers can always remove handlers
@@ -521,16 +487,15 @@ public class Logger {
return;
}
initHandler();
- synchronized(this){
+ synchronized (this) {
this.handlers.remove(handler);
}
}
/**
* Gets the filter used by this logger.
- *
+ *
* @return the filter used by this logger, may be {@code null}.
- * @since Android 1.0
*/
public Filter getFilter() {
return this.filter;
@@ -538,13 +503,12 @@ public class Logger {
/**
* Sets the filter used by this logger.
- *
+ *
* @param newFilter
* the filter to set, may be {@code null}.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setFilter(Filter newFilter) {
// Anonymous loggers can always set the filter
@@ -557,9 +521,8 @@ public class Logger {
/**
* Gets the logging level of this logger. A {@code null} level indicates
* that this logger inherits its parent's level.
- *
+ *
* @return the logging level of this logger.
- * @since Android 1.0
*/
public Level getLevel() {
return levelObjVal;
@@ -568,13 +531,12 @@ public class Logger {
/**
* Sets the logging level for this logger. A {@code null} level indicates
* that this logger will inherit its parent's level.
- *
+ *
* @param newLevel
* the logging level to set.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setLevel(Level newLevel) {
// Anonymous loggers can always set the level
@@ -590,10 +552,9 @@ public class Logger {
* Gets the flag which indicates whether to use the handlers of this
* logger's parent to publish incoming log records, potentially recursively
* up the namespace.
- *
+ *
* @return {@code true} if set to use parent's handlers, {@code false}
* otherwise.
- * @since Android 1.0
*/
public boolean getUseParentHandlers() {
return this.notifyParentHandlers;
@@ -602,13 +563,12 @@ public class Logger {
/**
* Sets the flag which indicates whether to use the handlers of this
* logger's parent, potentially recursively up the namespace.
- *
+ *
* @param notifyParentHandlers
* the new flag indicating whether to use the parent's handlers.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setUseParentHandlers(boolean notifyParentHandlers) {
// Anonymous loggers can always set the useParentHandlers flag
@@ -621,9 +581,8 @@ public class Logger {
/**
* Gets the nearest parent of this logger in the namespace, a {@code null}
* value will be returned if called on the root logger.
- *
+ *
* @return the parent of this logger in the namespace.
- * @since Android 1.0
*/
public Logger getParent() {
return parent;
@@ -633,14 +592,14 @@ public class Logger {
* Sets the parent of this logger in the namespace. This method should
* usually be used by the {@code LogManager} object only. This method does
* not check security.
- *
+ *
* @param newParent
* the parent logger to set.
- * @since Android 1.0
*/
void internalSetParent(Logger newParent) {
- //All hierarchy related modifications should get LogManager lock at first
- synchronized(LogManager.getLogManager()){
+ // All hierarchy related modifications should get LogManager lock at
+ // first
+ synchronized (LogManager.getLogManager()) {
parent = newParent;
// -- update level after setting a parent.
// -- if level == null we should inherit the parent's level
@@ -654,13 +613,12 @@ public class Logger {
/**
* Sets the parent of this logger in the namespace. This method should be
* used by the {@code LogManager} object only.
- *
+ *
* @param parent
* the parent logger to set.
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
public void setParent(Logger parent) {
if (null == parent) {
@@ -680,12 +638,10 @@ public class Logger {
childs.remove(child);
}
-
/**
* Gets the name of this logger, {@code null} for anonymous loggers.
- *
+ *
* @return the name of this logger.
- * @since Android 1.0
*/
public String getName() {
return this.name;
@@ -695,9 +651,8 @@ public class Logger {
* Gets the loaded resource bundle used by this logger to localize logging
* messages. If the value is {@code null}, the parent's resource bundle will be
* inherited.
- *
+ *
* @return the loaded resource bundle used by this logger.
- * @since Android 1.0
*/
public ResourceBundle getResourceBundle() {
return this.resBundle;
@@ -707,9 +662,8 @@ public class Logger {
* Gets the name of the loaded resource bundle used by this logger to
* localize logging messages. If the value is {@code null}, the parent's resource
* bundle name will be inherited.
- *
+ *
* @return the name of the loaded resource bundle used by this logger.
- * @since Android 1.0
*/
public String getResourceBundleName() {
return this.resBundleName;
@@ -734,12 +688,11 @@ public class Logger {
* Determines whether this logger will actually log messages of the
* specified level. The effective level used to do the determination may be
* inherited from its parent. The default level is {@code Level.INFO}.
- *
+ *
* @param l
* the level to check.
* @return {@code true} if this logger will actually log this level,
* otherwise {@code false}.
- * @since Android 1.0
*/
public boolean isLoggable(Level l) {
return internalIsLoggable(l);
@@ -775,12 +728,11 @@ public class Logger {
* Logs a message indicating that a method has been entered. A log record
* with log level {@code Level.FINER}, log message "ENTRY", the specified
* source class name and source method name is submitted for logging.
- *
+ *
* @param sourceClass
* the calling class name.
* @param sourceMethod
* the method name.
- * @since Android 1.0
*/
public void entering(String sourceClass, String sourceMethod) {
if (internalIsLoggable(Level.FINER)) {
@@ -798,14 +750,13 @@ public class Logger {
* with log level {@code Level.FINER}, log message "ENTRY", the specified
* source class name, source method name and one parameter is submitted for
* logging.
- *
+ *
* @param sourceClass
* the source class name.
* @param sourceMethod
* the source method name.
* @param param
* the parameter for the method call.
- * @since Android 1.0
*/
public void entering(String sourceClass, String sourceMethod, Object param) {
if (internalIsLoggable(Level.FINER)) {
@@ -824,14 +775,13 @@ public class Logger {
* with log level {@code Level.FINER}, log message "ENTRY", the specified
* source class name, source method name and array of parameters is
* submitted for logging.
- *
+ *
* @param sourceClass
* the source class name.
* @param sourceMethod
* the source method name.
* @param params
* an array of parameters for the method call.
- * @since Android 1.0
*/
public void entering(String sourceClass, String sourceMethod,
Object[] params) {
@@ -858,12 +808,11 @@ public class Logger {
* Logs a message indicating that a method is exited. A log record with log
* level {@code Level.FINER}, log message "RETURN", the specified source
* class name and source method name is submitted for logging.
- *
+ *
* @param sourceClass
* the calling class name.
* @param sourceMethod
* the method name.
- * @since Android 1.0
*/
public void exiting(String sourceClass, String sourceMethod) {
if (internalIsLoggable(Level.FINER)) {
@@ -880,14 +829,13 @@ public class Logger {
* Logs a message indicating that a method is exited. A log record with log
* level {@code Level.FINER}, log message "RETURN", the specified source
* class name, source method name and return value is submitted for logging.
- *
+ *
* @param sourceClass
* the source class name.
* @param sourceMethod
* the source method name.
* @param result
* the return value of the method call.
- * @since Android 1.0
*/
public void exiting(String sourceClass, String sourceMethod, Object result) {
if (internalIsLoggable(Level.FINER)) {
@@ -906,14 +854,13 @@ public class Logger {
* log level {@code Level.FINER}, log message "THROW", the specified source
* class name, source method name and the {@code Throwable} object is
* submitted for logging.
- *
+ *
* @param sourceClass
* the source class name.
* @param sourceMethod
* the source method name.
* @param thrown
* the {@code Throwable} object.
- * @since Android 1.0
*/
public void throwing(String sourceClass, String sourceMethod,
Throwable thrown) {
@@ -931,10 +878,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.SEVERE}; the message is transmitted
* to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void severe(String msg) {
if (internalIsLoggable(Level.SEVERE)) {
@@ -948,10 +894,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.WARNING}; the message is
* transmitted to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void warning(String msg) {
if (internalIsLoggable(Level.WARNING)) {
@@ -965,10 +910,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.INFO}; the message is transmitted
* to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void info(String msg) {
if (internalIsLoggable(Level.INFO)) {
@@ -982,10 +926,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.CONFIG}; the message is transmitted
* to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void config(String msg) {
if (internalIsLoggable(Level.CONFIG)) {
@@ -999,10 +942,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.FINE}; the message is transmitted
* to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void fine(String msg) {
if (internalIsLoggable(Level.FINE)) {
@@ -1016,10 +958,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.FINER}; the message is transmitted
* to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void finer(String msg) {
if (internalIsLoggable(Level.FINER)) {
@@ -1033,10 +974,9 @@ public class Logger {
/**
* Logs a message of level {@code Level.FINEST}; the message is transmitted
* to all subscribed handlers.
- *
+ *
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void finest(String msg) {
if (internalIsLoggable(Level.FINEST)) {
@@ -1050,12 +990,11 @@ public class Logger {
/**
* Logs a message of the specified level. The message is transmitted to all
* subscribed handlers.
- *
+ *
* @param logLevel
* the level of the specified message.
* @param msg
* the message to log.
- * @since Android 1.0
*/
public void log(Level logLevel, String msg) {
if (internalIsLoggable(logLevel)) {
@@ -1069,14 +1008,13 @@ public class Logger {
/**
* Logs a message of the specified level with the supplied parameter. The
* message is then transmitted to all subscribed handlers.
- *
+ *
* @param logLevel
* the level of the given message.
* @param msg
* the message to log.
* @param param
* the parameter associated with the event that is logged.
- * @since Android 1.0
*/
public void log(Level logLevel, String msg, Object param) {
if (internalIsLoggable(logLevel)) {
@@ -1091,14 +1029,13 @@ public class Logger {
/**
* Logs a message of the specified level with the supplied parameter array.
* The message is then transmitted to all subscribed handlers.
- *
+ *
* @param logLevel
* the level of the given message
* @param msg
* the message to log.
* @param params
* the parameter array associated with the event that is logged.
- * @since Android 1.0
*/
public void log(Level logLevel, String msg, Object[] params) {
if (internalIsLoggable(logLevel)) {
@@ -1113,7 +1050,7 @@ public class Logger {
/**
* Logs a message of the specified level with the supplied {@code Throwable}
* object. The message is then transmitted to all subscribed handlers.
- *
+ *
* @param logLevel
* the level of the given message.
* @param msg
@@ -1121,7 +1058,6 @@ public class Logger {
* @param thrown
* the {@code Throwable} object associated with the event that is
* logged.
- * @since Android 1.0
*/
public void log(Level logLevel, String msg, Throwable thrown) {
if (internalIsLoggable(logLevel)) {
@@ -1144,10 +1080,9 @@ public class Logger {
* logging action, subclasses of this class can override this method to
* catch all logging activities.
* </p>
- *
+ *
* @param record
* the log record to be logged.
- * @since Android 1.0
*/
public void log(LogRecord record) {
if (internalIsLoggable(record.getLevel())) {
@@ -1158,8 +1093,7 @@ public class Logger {
}
initHandler();
/*
- * call the handlers of this logger, throw any exception that
- * occurs
+ * call the handlers of this logger, throw any exception that occurs
*/
Handler[] allHandlers = getHandlers();
for (Handler element : allHandlers) {
@@ -1182,7 +1116,7 @@ public class Logger {
/**
* Logs a message of the given level with the specified source class name
* and source method name.
- *
+ *
* @param logLevel
* the level of the given message.
* @param sourceClass
@@ -1191,7 +1125,6 @@ public class Logger {
* the source method name.
* @param msg
* the message to be logged.
- * @since Android 1.0
*/
public void logp(Level logLevel, String sourceClass, String sourceMethod,
String msg) {
@@ -1208,7 +1141,7 @@ public class Logger {
/**
* Logs a message of the given level with the specified source class name,
* source method name and parameter.
- *
+ *
* @param logLevel
* the level of the given message
* @param sourceClass
@@ -1219,7 +1152,6 @@ public class Logger {
* the message to be logged
* @param param
* the parameter associated with the event that is logged.
- * @since Android 1.0
*/
public void logp(Level logLevel, String sourceClass, String sourceMethod,
String msg, Object param) {
@@ -1237,7 +1169,7 @@ public class Logger {
/**
* Logs a message of the given level with the specified source class name,
* source method name and parameter array.
- *
+ *
* @param logLevel
* the level of the given message.
* @param sourceClass
@@ -1248,7 +1180,6 @@ public class Logger {
* the message to be logged.
* @param params
* the parameter array associated with the event that is logged.
- * @since Android 1.0
*/
public void logp(Level logLevel, String sourceClass, String sourceMethod,
String msg, Object[] params) {
@@ -1266,7 +1197,7 @@ public class Logger {
/**
* Logs a message of the given level with the specified source class name,
* source method name and {@code Throwable} object.
- *
+ *
* @param logLevel
* the level of the given message.
* @param sourceClass
@@ -1277,7 +1208,6 @@ public class Logger {
* the message to be logged.
* @param thrown
* the {@code Throwable} object.
- * @since Android 1.0
*/
public void logp(Level logLevel, String sourceClass, String sourceMethod,
String msg, Throwable thrown) {
@@ -1297,7 +1227,7 @@ public class Logger {
* and source method name, using the given resource bundle to localize the
* message. If {@code bundleName} is null, the empty string or not valid then
* the message is not localized.
- *
+ *
* @param logLevel
* the level of the given message.
* @param sourceClass
@@ -1308,7 +1238,6 @@ public class Logger {
* the name of the resource bundle used to localize the message.
* @param msg
* the message to be logged.
- * @since Android 1.0
*/
public void logrb(Level logLevel, String sourceClass, String sourceMethod,
String bundleName, String msg) {
@@ -1334,7 +1263,7 @@ public class Logger {
* source method name and parameter, using the given resource bundle to
* localize the message. If {@code bundleName} is null, the empty string
* or not valid then the message is not localized.
- *
+ *
* @param logLevel
* the level of the given message.
* @param sourceClass
@@ -1347,7 +1276,6 @@ public class Logger {
* the message to be logged.
* @param param
* the parameter associated with the event that is logged.
- * @since Android 1.0
*/
public void logrb(Level logLevel, String sourceClass, String sourceMethod,
String bundleName, String msg, Object param) {
@@ -1374,7 +1302,7 @@ public class Logger {
* source method name and parameter array, using the given resource bundle
* to localize the message. If {@code bundleName} is null, the empty string
* or not valid then the message is not localized.
- *
+ *
* @param logLevel
* the level of the given message.
* @param sourceClass
@@ -1387,7 +1315,6 @@ public class Logger {
* the message to be logged.
* @param params
* the parameter array associated with the event that is logged.
- * @since Android 1.0
*/
public void logrb(Level logLevel, String sourceClass, String sourceMethod,
String bundleName, String msg, Object[] params) {
@@ -1414,7 +1341,7 @@ public class Logger {
* source method name and {@code Throwable} object, using the given resource
* bundle to localize the message. If {@code bundleName} is null, the empty
* string or not valid then the message is not localized.
- *
+ *
* @param logLevel
* the level of the given message
* @param sourceClass
@@ -1427,7 +1354,6 @@ public class Logger {
* the message to be logged.
* @param thrown
* the {@code Throwable} object.
- * @since Android 1.0
*/
public void logrb(Level logLevel, String sourceClass, String sourceMethod,
String bundleName, String msg, Throwable thrown) {
@@ -1459,25 +1385,30 @@ public class Logger {
}
void setManager(LogManager manager) {
- if(this.manager != manager){
+ if (this.manager != manager) {
this.manager = manager;
- handlerInited = false;
+ handlerInited = false;
}
- //init level here, but let handlers be for lazy loading
- String configedLevel = manager.getProperty(name+ ".level"); //$NON-NLS-1$
+ // init level here, but let handlers be for lazy loading
+ final String configedLevel = manager.getProperty(name + ".level"); //$NON-NLS-1$
if (null != configedLevel) {
try {
- setLevel(Level.parse(configedLevel));
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ setLevel(Level.parse(configedLevel));
+ return null;
+ }
+ });
} catch (IllegalArgumentException e) {
- //ignore
+ // ignore
}
- }
+ }
}
synchronized void reset() {
levelObjVal = null;
levelIntVal = Level.INFO.intValue();
- if(handlers != null){
+ if (handlers != null) {
for (Handler element : handlers) {
// close all handlers, when unknown exceptions happen,
// ignore them and go on
@@ -1492,4 +1423,3 @@ public class Logger {
handlerInited = false;
}
}
-
diff --git a/logging/src/main/java/java/util/logging/LoggingMXBean.java b/logging/src/main/java/java/util/logging/LoggingMXBean.java
index f6b49a6..18cc4cc 100644
--- a/logging/src/main/java/java/util/logging/LoggingMXBean.java
+++ b/logging/src/main/java/java/util/logging/LoggingMXBean.java
@@ -25,29 +25,28 @@ import java.util.List;
* The ObjectName for identifying the {@code LoggingMXBean} in a bean server is
* {@link LogManager#LOGGING_MXBEAN_NAME}.
* </p>
- *
- * @since Android 1.0
+ *
+ * @since 1.5
*/
public interface LoggingMXBean {
+
/**
* Gets the string value of the logging level of a logger. An empty string
* is returned when the logger's level is defined by its parent. A
* {@code null} is returned if the specified logger does not exist.
- *
+ *
* @param loggerName
* the name of the logger lookup.
* @return a {@code String} if the logger is found, otherwise {@code null}.
* @see Level#getName()
- * @since Android 1.0
*/
String getLoggerLevel(String loggerName);
/**
* Gets a list of all currently registered logger names. This is performed
* using the {@link LogManager#getLoggerNames()}.
- *
+ *
* @return a list of logger names.
- * @since Android 1.0
*/
List<String> getLoggerNames();
@@ -55,18 +54,17 @@ public interface LoggingMXBean {
* Gets the name of the parent logger of a logger. If the logger doesn't
* exist then {@code null} is returned. If the logger is the root logger,
* then an empty {@code String} is returned.
- *
+ *
* @param loggerName
* the name of the logger to lookup.
* @return a {@code String} if the logger was found, otherwise {@code null}.
- * @since Android 1.0
*/
String getParentLoggerName(String loggerName);
/**
* Sets the log level of a logger. LevelName set to {@code null} means the
* level is inherited from the nearest non-null ancestor.
- *
+ *
* @param loggerName
* the name of the logger to set the level on, which must not be
* {@code null}.
@@ -79,7 +77,6 @@ public interface LoggingMXBean {
* if a security manager exists and the caller doesn't have
* LoggingPermission("control").
* @see Level#parse(String)
- * @since Android 1.0
*/
void setLoggerLevel(String loggerName, String levelName);
}
diff --git a/logging/src/main/java/java/util/logging/LoggingPermission.java b/logging/src/main/java/java/util/logging/LoggingPermission.java
index fb6d4f8..aa41a2c 100644
--- a/logging/src/main/java/java/util/logging/LoggingPermission.java
+++ b/logging/src/main/java/java/util/logging/LoggingPermission.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.io.Serializable;
@@ -27,20 +26,12 @@ import org.apache.harmony.logging.internal.nls.Messages;
/**
* The permission required to control the logging when run with a
* {@code SecurityManager}.
- *
*/
public final class LoggingPermission extends BasicPermission implements Guard,
Serializable {
- //for serialization compatibility with J2SE 1.4.2
- private static final long serialVersionUID =63564341580231582L;
-
-
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
+ // for serialization compatibility with J2SE 1.4.2
+ private static final long serialVersionUID = 63564341580231582L;
/**
* Constructs a {@code LoggingPermission} object required to control the
@@ -50,7 +41,7 @@ public final class LoggingPermission extends BasicPermission implements Guard,
* and depends on the security policy file, therefore programmers shouldn't
* normally use them directly.
* </p>
- *
+ *
* @param name
* currently must be "control".
* @param actions
@@ -71,4 +62,3 @@ public final class LoggingPermission extends BasicPermission implements Guard,
}
}
-
diff --git a/logging/src/main/java/java/util/logging/MemoryHandler.java b/logging/src/main/java/java/util/logging/MemoryHandler.java
index c1e8670..3312083 100644
--- a/logging/src/main/java/java/util/logging/MemoryHandler.java
+++ b/logging/src/main/java/java/util/logging/MemoryHandler.java
@@ -22,7 +22,6 @@ import java.security.PrivilegedExceptionAction;
import org.apache.harmony.logging.internal.nls.Messages;
-
/**
* A {@code Handler} put the description of log events into a cycled memory
* buffer.
@@ -30,68 +29,61 @@ import org.apache.harmony.logging.internal.nls.Messages;
* Mostly this {@code MemoryHandler} just puts the given {@code LogRecord} into
* the internal buffer and doesn't perform any formatting or any other process.
* When the buffer is full, the earliest buffered records will be discarded.
- * </p>
* <p>
* Every {@code MemoryHandler} has a target handler, and push action can be
* triggered so that all buffered records will be output to the target handler
* and normally the latter will publish the records. After the push action, the
* buffer will be cleared.
- * </p>
* <p>
- * The push action can be triggered in three ways:
- * <ul>
- * <li>The push method is called explicitly</li>
- * <li>When a new {@code LogRecord} is put into the internal buffer, and it has
- * a level which is not less than the specified push level.</li>
- * <li>A subclass extends this {@code MemoryHandler} and call push method
- * implicitly according to some criteria.</li>
- * </ul>
- * </p>
+ * The push method can be called directly, but will also be called automatically
+ * if a new <code>LogRecord</code> is added that has a level greater than or
+ * equal to than the value defined for the property
+ * java.util.logging.MemoryHandler.push.
* <p>
* {@code MemoryHandler} will read following {@code LogManager} properties for
* initialization, if given properties are not defined or has invalid values,
* default value will be used.
* <ul>
- * <li>java.util.logging.MemoryHandler.level specifies the level for this
- * {@code Handler}, defaults to {@code Level.ALL}.</li>
* <li>java.util.logging.MemoryHandler.filter specifies the {@code Filter}
* class name, defaults to no {@code Filter}.</li>
- * <li>java.util.logging.MemoryHandler.size specifies the buffer size in number
- * of {@code LogRecord}, defaults to 1000.</li>
+ * <li>java.util.logging.MemoryHandler.level specifies the level for this
+ * {@code Handler}, defaults to {@code Level.ALL}.</li>
* <li>java.util.logging.MemoryHandler.push specifies the push level, defaults
* to level.SEVERE.</li>
+ * <li>java.util.logging.MemoryHandler.size specifies the buffer size in number
+ * of {@code LogRecord}, defaults to 1000.</li>
* <li>java.util.logging.MemoryHandler.target specifies the class of the target
* {@code Handler}, no default value, which means this property must be
* specified either by property setting or by constructor.</li>
* </ul>
- * </p>
*/
public class MemoryHandler extends Handler {
- //default maximum buffered number of LogRecord
+ // default maximum buffered number of LogRecord
private static final int DEFAULT_SIZE = 1000;
- //target handler
+
+ // target handler
private Handler target;
-
- //buffer size
+
+ // buffer size
private int size = DEFAULT_SIZE;
-
- //push level
+
+ // push level
private Level push = Level.SEVERE;
- //LogManager instance for convenience
+ // LogManager instance for convenience
private final LogManager manager = LogManager.getLogManager();
-
- //buffer
+
+ // buffer
private LogRecord[] buffer;
-
- //current position in buffer
+
+ // current position in buffer
private int cursor;
-
+
/**
* Default constructor, construct and init a {@code MemoryHandler} using
* {@code LogManager} properties or default values.
- *
+ *
* @throws RuntimeException
* if property value are invalid and no default value could be
* used.
@@ -99,55 +91,57 @@ public class MemoryHandler extends Handler {
public MemoryHandler() {
super();
String className = this.getClass().getName();
- //init target
- final String targetName = manager.getProperty(className+".target"); //$NON-NLS-1$
+ // init target
+ final String targetName = manager.getProperty(className + ".target"); //$NON-NLS-1$
try {
- Class<?> targetClass = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>(){
- public Class<?> run() throws Exception{
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if(loader == null){
- loader = ClassLoader.getSystemClassLoader();
- }
- return loader.loadClass(targetName);
- }
- });
+ Class<?> targetClass = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws Exception {
+ ClassLoader loader = Thread.currentThread()
+ .getContextClassLoader();
+ if (loader == null) {
+ loader = ClassLoader.getSystemClassLoader();
+ }
+ return loader.loadClass(targetName);
+ }
+ });
target = (Handler) targetClass.newInstance();
} catch (Exception e) {
// logging.10=Cannot load target handler:{0}
throw new RuntimeException(Messages.getString("logging.10", //$NON-NLS-1$
targetName));
}
- //init size
- String sizeString = manager.getProperty(className+".size"); //$NON-NLS-1$
+ // init size
+ String sizeString = manager.getProperty(className + ".size"); //$NON-NLS-1$
if (null != sizeString) {
try {
size = Integer.parseInt(sizeString);
- if(size <= 0){
+ if (size <= 0) {
size = DEFAULT_SIZE;
}
} catch (Exception e) {
- printInvalidPropMessage(className+".size", sizeString, e); //$NON-NLS-1$
+ printInvalidPropMessage(className + ".size", sizeString, e); //$NON-NLS-1$
}
}
- //init push level
- String pushName = manager.getProperty(className+".push"); //$NON-NLS-1$
+ // init push level
+ String pushName = manager.getProperty(className + ".push"); //$NON-NLS-1$
if (null != pushName) {
try {
push = Level.parse(pushName);
} catch (Exception e) {
- printInvalidPropMessage(className+".push", pushName, e); //$NON-NLS-1$
+ printInvalidPropMessage(className + ".push", pushName, e); //$NON-NLS-1$
}
}
- //init other properties which are common for all Handler
- initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$
+ // init other properties which are common for all Handler
+ initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$
buffer = new LogRecord[size];
}
-
+
/**
* Construct and init a {@code MemoryHandler} using given target, size and
* push level, other properties using {@code LogManager} properties or
* default values.
- *
+ *
* @param target
* the given {@code Handler} to output
* @param size
@@ -156,7 +150,7 @@ public class MemoryHandler extends Handler {
* @param pushLevel
* the push level
* @throws IllegalArgumentException
- * if {@code size}<=0
+ * if {@code size <= 0}
* @throws RuntimeException
* if property value are invalid and no default value could be
* used.
@@ -171,13 +165,13 @@ public class MemoryHandler extends Handler {
this.target = target;
this.size = size;
this.push = pushLevel;
- initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$
+ initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$
buffer = new LogRecord[size];
}
-
+
/**
* Close this handler and target handler, free all associated resources.
- *
+ *
* @throws SecurityException
* if security manager exists and it determines that caller does
* not have the required permissions to control this handler.
@@ -204,7 +198,7 @@ public class MemoryHandler extends Handler {
* Furthermore if the record's level is not less than the push level, the
* push action is triggered to output all the buffered records to the target
* handler, and the target handler will publish them.
- *
+ *
* @param record
* the log record
*/
@@ -225,7 +219,7 @@ public class MemoryHandler extends Handler {
/**
* Return the push level.
- *
+ *
* @return the push level
*/
public Level getPushLevel() {
@@ -233,18 +227,14 @@ public class MemoryHandler extends Handler {
}
/**
- * <p>
* Check if given {@code LogRecord} would be put into this
* {@code MemoryHandler}'s internal buffer.
- * </p>
* <p>
* The given {@code LogRecord} is loggable if and only if it has appropriate
* level and it pass any associated filter's check.
- * </p>
* <p>
* Note that the push level is not used for this check.
- * </p>
- *
+ *
* @param record
* the given {@code LogRecord}
* @return the given {@code LogRecord} if it should be logged, {@code false}
@@ -261,13 +251,13 @@ public class MemoryHandler extends Handler {
*/
public void push() {
for (int i = cursor; i < size; i++) {
- if(null != buffer[i]) {
+ if (null != buffer[i]) {
target.publish(buffer[i]);
}
buffer[i] = null;
}
for (int i = 0; i < cursor; i++) {
- if(null != buffer[i]) {
+ if (null != buffer[i]) {
target.publish(buffer[i]);
}
buffer[i] = null;
@@ -276,15 +266,15 @@ public class MemoryHandler extends Handler {
}
/**
- * Set the push level. The push level is used to check the push action
+ * Set the push level. The push level is used to check the push action
* triggering. When a new {@code LogRecord} is put into the internal
- * buffer and its level is not less than the push level, the push action
+ * buffer and its level is not less than the push level, the push action
* will be triggered. Note that set new push level won't trigger push action.
- *
+ *
* @param newLevel
* the new level to set.
* @throws SecurityException
- * if security manager exists and it determines that caller
+ * if security manager exists and it determines that caller
* does not have the required permissions to control this handler.
*/
public void setPushLevel(Level newLevel) {
diff --git a/logging/src/main/java/java/util/logging/SimpleFormatter.java b/logging/src/main/java/java/util/logging/SimpleFormatter.java
index 1595796..def4ad3 100644
--- a/logging/src/main/java/java/util/logging/SimpleFormatter.java
+++ b/logging/src/main/java/java/util/logging/SimpleFormatter.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.io.PrintWriter;
@@ -26,13 +25,10 @@ import java.util.Date;
/**
* {@code SimpleFormatter} can be used to print a summary of the information
* contained in a {@code LogRecord} object in a human readable format.
- * @since Android 1.0
*/
public class SimpleFormatter extends Formatter {
/**
* Constructs a new {@code SimpleFormatter}.
- *
- * @since Android 1.0
*/
public SimpleFormatter() {
super();
@@ -41,11 +37,10 @@ public class SimpleFormatter extends Formatter {
/**
* Converts a {@link LogRecord} object into a human readable string
* representation.
- *
+ *
* @param r
* the log record to be formatted into a string.
* @return the formatted string.
- * @since Android 1.0
*/
@Override
public String format(LogRecord r) {
@@ -53,7 +48,8 @@ public class SimpleFormatter extends Formatter {
sb.append(MessageFormat.format("{0, date} {0, time} ", //$NON-NLS-1$
new Object[] { new Date(r.getMillis()) }));
sb.append(r.getSourceClassName()).append(" "); //$NON-NLS-1$
- sb.append(r.getSourceMethodName()).append(LogManager.getSystemLineSeparator()); //$NON-NLS-1$
+ sb.append(r.getSourceMethodName()).append(
+ LogManager.getSystemLineSeparator());
sb.append(r.getLevel().getName()).append(": "); //$NON-NLS-1$
sb.append(formatMessage(r)).append(LogManager.getSystemLineSeparator());
if (null != r.getThrown()) {
@@ -66,7 +62,7 @@ public class SimpleFormatter extends Formatter {
t.printStackTrace(pw);
sb.append(sw.toString());
} finally {
- if(pw != null){
+ if (pw != null) {
try {
pw.close();
} catch (Exception e) {
@@ -78,4 +74,3 @@ public class SimpleFormatter extends Formatter {
return sb.toString();
}
}
-
diff --git a/logging/src/main/java/java/util/logging/SocketHandler.java b/logging/src/main/java/java/util/logging/SocketHandler.java
index 8626007..38cfd64 100644
--- a/logging/src/main/java/java/util/logging/SocketHandler.java
+++ b/logging/src/main/java/java/util/logging/SocketHandler.java
@@ -15,12 +15,11 @@
* limitations under the License.
*/
-
package java.util.logging;
-import java.net.Socket;
import java.io.BufferedOutputStream;
import java.io.IOException;
+import java.net.Socket;
import org.apache.harmony.logging.internal.nls.Messages;
@@ -48,16 +47,14 @@ import org.apache.harmony.logging.internal.nls.Messages;
* <li>java.util.logging.SocketHandler.encoding specifies the port number that
* this handler should connect to. There's no default value for this property.
* </ul>
- * </p>
* <p>
* This handler buffers the outgoing messages, but flushes each time a log
* record has been published.
- * </p>
* <p>
* This class is not thread-safe.
- * </p>
*/
public class SocketHandler extends StreamHandler {
+
// default level
private static final String DEFAULT_LEVEL = "ALL"; //$NON-NLS-1$
@@ -71,7 +68,7 @@ public class SocketHandler extends StreamHandler {
* Constructs a {@code SocketHandler} object using the properties read by
* the log manager, including the host name and port number. Default
* formatting uses the XMLFormatter class and level is set to ALL.
- *
+ *
* @throws IOException
* if failed to connect to the specified host and port.
* @throws IllegalArgumentException
@@ -92,7 +89,7 @@ public class SocketHandler extends StreamHandler {
* Constructs a {@code SocketHandler} object using the specified host name
* and port number together with other properties read by the log manager.
* Default formatting uses the XMLFormatter class and level is set to ALL.
- *
+ *
* @param host
* the host name
* @param port
@@ -146,7 +143,7 @@ public class SocketHandler extends StreamHandler {
/**
* Closes this handler. The network connection to the host is also closed.
- *
+ *
* @throws SecurityException
* If a security manager determines that the caller does not
* have the required permission to control this handler.
@@ -168,7 +165,7 @@ public class SocketHandler extends StreamHandler {
/**
* Logs a record if necessary. A flush operation will be done afterwards.
- *
+ *
* @param record
* the log record to be logged.
*/
@@ -177,5 +174,4 @@ public class SocketHandler extends StreamHandler {
super.publish(record);
super.flush();
}
-
}
diff --git a/logging/src/main/java/java/util/logging/StreamHandler.java b/logging/src/main/java/java/util/logging/StreamHandler.java
index ee12190..7049d45 100644
--- a/logging/src/main/java/java/util/logging/StreamHandler.java
+++ b/logging/src/main/java/java/util/logging/StreamHandler.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.io.OutputStream;
@@ -30,30 +29,26 @@ import org.apache.harmony.logging.internal.nls.Messages;
* is, objects of the class {@link java.io.OutputStream}.
* <p>
* A {@code StreamHandler} object reads the following properties from the log
- * manager to initialize itself:
+ * manager to initialize itself. A default value will be used if a property is
+ * not found or has an invalid value.
* <ul>
- * <li>java.util.logging.StreamHandler.level specifies the logging level,
- * defaults to {@code Level.INFO} if this property is not found or has an
- * invalid value.
+ * <li>java.util.logging.StreamHandler.encoding specifies the encoding this
+ * handler will use to encode log messages. Default is the encoding used by the
+ * current platform.
* <li>java.util.logging.StreamHandler.filter specifies the name of the filter
- * class to be associated with this handler, defaults to {@code null} if this
- * property is not found or has an invalid value.
+ * class to be associated with this handler. No <code>Filter</code> is used by
+ * default.
* <li>java.util.logging.StreamHandler.formatter specifies the name of the
- * formatter class to be associated with this handler, defaults to
- * {@code java.util.logging.SimpleFormatter} if this property is not found or
- * has an invalid value.
- * <li>java.util.logging.StreamHandler.encoding specifies the encoding this
- * handler will use to encode log messages, defaults to {@code null} if this
- * property is not found or has an invalid value.
+ * formatter class to be associated with this handler. Default is
+ * {@code java.util.logging.SimpleFormatter}.
+ * <li>java.util.logging.StreamHandler.level specifies the logging level.
+ * Defaults is {@code Level.INFO}.
* </ul>
- * </p>
* <p>
* This class is not thread-safe.
- * </p>
- *
- * @since Android 1.0
*/
public class StreamHandler extends Handler {
+
// the output stream this handler writes to
private OutputStream os;
@@ -66,11 +61,9 @@ public class StreamHandler extends Handler {
/**
* Constructs a {@code StreamHandler} object. The new stream handler
* does not have an associated output stream.
- *
- * @since Android 1.0
*/
public StreamHandler() {
- initProperties("INFO", null, "java.util.logging.SimpleFormatter", //$NON-NLS-1$//$NON-NLS-2$
+ initProperties("INFO", null, "java.util.logging.SimpleFormatter", //$NON-NLS-1$//$NON-NLS-2$
null);
this.os = null;
this.writer = null;
@@ -80,7 +73,7 @@ public class StreamHandler extends Handler {
/**
* Constructs a {@code StreamHandler} object with the supplied output
* stream. Default properties are read.
- *
+ *
* @param os
* the output stream this handler writes to.
*/
@@ -106,14 +99,13 @@ public class StreamHandler extends Handler {
/**
* Constructs a {@code StreamHandler} object with the supplied output stream
* and formatter.
- *
+ *
* @param os
* the output stream this handler writes to.
* @param formatter
* the formatter this handler uses to format the output.
* @throws NullPointerException
* if {@code os} or {@code formatter} is {@code null}.
- * @since Android 1.0
*/
public StreamHandler(OutputStream os, Formatter formatter) {
this();
@@ -160,7 +152,7 @@ public class StreamHandler extends Handler {
/**
* Sets the output stream this handler writes to. Note it does nothing else.
- *
+ *
* @param newOs
* the new output stream
*/
@@ -168,13 +160,12 @@ public class StreamHandler extends Handler {
this.os = newOs;
}
-
/**
* Sets the output stream this handler writes to. If there's an existing
* output stream, the tail string of the associated formatter will be
- * written to it. Then it will be flushed, closed and replaced with
+ * written to it. Then it will be flushed, closed and replaced with
* {@code os}.
- *
+ *
* @param os
* the new output stream.
* @throws SecurityException
@@ -197,7 +188,7 @@ public class StreamHandler extends Handler {
/**
* Sets the character encoding used by this handler. A {@code null} value
* indicates that the default encoding should be used.
- *
+ *
* @param encoding
* the character encoding to set.
* @throws SecurityException
@@ -205,12 +196,11 @@ public class StreamHandler extends Handler {
* have the required permission.
* @throws UnsupportedEncodingException
* if the specified encoding is not supported by the runtime.
- * @since Android 1.0
*/
@Override
public void setEncoding(String encoding) throws SecurityException,
UnsupportedEncodingException {
- //flush first before set new encoding
+ // flush first before set new encoding
this.flush();
super.setEncoding(encoding);
// renew writer only if the writer exists
@@ -234,7 +224,7 @@ public class StreamHandler extends Handler {
/**
* Closes this handler, but the underlying output stream is only closed if
* {@code closeStream} is {@code true}. Security is not checked.
- *
+ *
* @param closeStream
* whether to close the underlying output stream.
*/
@@ -264,11 +254,10 @@ public class StreamHandler extends Handler {
* this handler is written out. A flush operation and a subsequent close
* operation is then performed upon the output stream. Client applications
* should not use a handler after closing it.
- *
+ *
* @throws SecurityException
* if a security manager determines that the caller does not
* have the required permission.
- * @since Android 1.0
*/
@Override
public void close() {
@@ -278,8 +267,6 @@ public class StreamHandler extends Handler {
/**
* Flushes any buffered output.
- *
- * @since Android 1.0
*/
@Override
public void flush() {
@@ -291,7 +278,8 @@ public class StreamHandler extends Handler {
this.os.flush();
}
} catch (Exception e) {
- // logging.16=Exception occurred while flushing the output stream.
+ // logging.16=Exception occurred while flushing the output
+ // stream.
getErrorManager().error(Messages.getString("logging.16"), //$NON-NLS-1$
e, ErrorManager.FLUSH_FAILURE);
}
@@ -309,10 +297,9 @@ public class StreamHandler extends Handler {
* </ul>
* If it is the first time a log record is written out, the head string of
* the formatter associated with this handler is written out first.
- *
+ *
* @param record
* the log record to be logged.
- * @since Android 1.0
*/
@Override
public synchronized void publish(LogRecord record) {
@@ -325,7 +312,8 @@ public class StreamHandler extends Handler {
try {
msg = getFormatter().format(record);
} catch (Exception e) {
- // logging.17=Exception occurred while formatting the log record.
+ // logging.17=Exception occurred while formatting the log
+ // record.
getErrorManager().error(Messages.getString("logging.17"), //$NON-NLS-1$
e, ErrorManager.FORMAT_FAILURE);
}
@@ -345,13 +333,11 @@ public class StreamHandler extends Handler {
* {@code false}.
* <p>
* Notice : Case of no output stream will return {@code false}.
- * </p>
- *
+ *
* @param record
* the log record to be checked.
* @return {@code true} if {@code record} needs to be logged, {@code false}
* otherwise.
- * @since Android 1.0
*/
@Override
public boolean isLoggable(LogRecord record) {
@@ -363,5 +349,4 @@ public class StreamHandler extends Handler {
}
return false;
}
-
}
diff --git a/logging/src/main/java/java/util/logging/XMLFormatter.java b/logging/src/main/java/java/util/logging/XMLFormatter.java
index 6279d8c..ff96813 100644
--- a/logging/src/main/java/java/util/logging/XMLFormatter.java
+++ b/logging/src/main/java/java/util/logging/XMLFormatter.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.security.AccessController;
@@ -30,8 +29,6 @@ import java.util.ResourceBundle;
* {@code XMLFormatter} uses the output handler's encoding if it is specified,
* otherwise the default platform encoding is used instead. UTF-8 is the
* recommended encoding.
- *
- * @since Android 1.0
*/
public class XMLFormatter extends Formatter {
@@ -42,8 +39,6 @@ public class XMLFormatter extends Formatter {
/**
* Constructs a new {@code XMLFormatter}.
- *
- * @since Android 1.0
*/
public XMLFormatter() {
super();
@@ -51,61 +46,63 @@ public class XMLFormatter extends Formatter {
/**
* Converts a {@code LogRecord} into an XML string.
- *
+ *
* @param r
* the log record to be formatted.
* @return the log record formatted as an XML string.
- * @since Android 1.0
*/
+ @SuppressWarnings("nls")
@Override
public String format(LogRecord r) {
- //call a method of LogRecord to ensure not null
+ // call a method of LogRecord to ensure not null
long time = r.getMillis();
- //format to date
- String date = MessageFormat.format("{0, date} {0, time}", //$NON-NLS-1$
+ // format to date
+ String date = MessageFormat.format("{0, date} {0, time}",
new Object[] { new Date(time) });
StringBuilder sb = new StringBuilder();
- sb.append(("<record>")).append(lineSeperator); //$NON-NLS-1$
- sb.append(indent).append(("<date>")).append(date).append(("</date>")) //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append(("<record>")).append(lineSeperator);
+ sb.append(indent).append(("<date>")).append(date).append(("</date>"))
.append(lineSeperator);
- sb.append(indent).append(("<millis>")).append(time).append( //$NON-NLS-1$
- ("</millis>")).append(lineSeperator); //$NON-NLS-1$
- sb.append(indent).append(("<sequence>")).append(r.getSequenceNumber()) //$NON-NLS-1$
- .append(("</sequence>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append(("<millis>")).append(time).append(
+ ("</millis>")).append(lineSeperator);
+ sb.append(indent).append(("<sequence>")).append(r.getSequenceNumber())
+ .append(("</sequence>")).append(lineSeperator);
if (null != r.getLoggerName()) {
- sb.append(indent).append(("<logger>")).append(r.getLoggerName()) //$NON-NLS-1$
- .append(("</logger>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append(("<logger>")).append(r.getLoggerName())
+ .append(("</logger>")).append(lineSeperator);
}
- sb.append(indent).append(("<level>")).append(r.getLevel().getName()) //$NON-NLS-1$
- .append(("</level>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append(("<level>")).append(r.getLevel().getName())
+ .append(("</level>")).append(lineSeperator);
if (null != r.getSourceClassName()) {
- sb.append(indent).append(("<class>")) //$NON-NLS-1$
- .append(r.getSourceClassName()).append(("</class>")) //$NON-NLS-1$
+ sb.append(indent).append(("<class>"))
+ .append(r.getSourceClassName()).append(("</class>"))
.append(lineSeperator);
}
if (null != r.getSourceMethodName()) {
- sb.append(indent).append(("<method>")).append( //$NON-NLS-1$
- r.getSourceMethodName()).append(("</method>")).append( //$NON-NLS-1$
+ sb.append(indent).append(("<method>")).append(
+ r.getSourceMethodName()).append(("</method>")).append(
lineSeperator);
}
- sb.append(indent).append(("<thread>")).append(r.getThreadID()).append( //$NON-NLS-1$
- ("</thread>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append(("<thread>")).append(r.getThreadID()).append(
+ ("</thread>")).append(lineSeperator);
formatMessages(r, sb);
Object[] params;
if ((params = r.getParameters()) != null) {
for (Object element : params) {
- sb.append(indent).append(("<param>")).append(element).append( //$NON-NLS-1$
- ("</param>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append(("<param>")).append(element).append(
+ ("</param>")).append(lineSeperator);
}
}
formatThrowable(r, sb);
- sb.append(("</record>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(("</record>")).append(lineSeperator);
return sb.toString();
}
+ @SuppressWarnings("nls")
private void formatMessages(LogRecord r, StringBuilder sb) {
- //get localized message if has, but don't call Formatter.formatMessage to parse pattern string
+ // get localized message if has, but don't call Formatter.formatMessage
+ // to parse pattern string
ResourceBundle rb = r.getResourceBundle();
String pattern = r.getMessage();
if (null != rb && null != pattern) {
@@ -118,49 +115,50 @@ public class XMLFormatter extends Formatter {
if (message == null) {
message = pattern;
- sb.append(indent).append(("<message>")).append(message).append( //$NON-NLS-1$
- ("</message>")).append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append(("<message>")).append(message).append(
+ ("</message>")).append(lineSeperator);
} else {
- sb.append(indent).append(("<message>")).append(message).append( //$NON-NLS-1$
- ("</message>")).append(lineSeperator); //$NON-NLS-1$
- sb.append(indent).append(("<key>")).append(pattern).append( //$NON-NLS-1$
- ("</key>")).append(lineSeperator); //$NON-NLS-1$
- sb.append(indent).append(("<catalog>")).append( //$NON-NLS-1$
- r.getResourceBundleName()).append(("</catalog>")) //$NON-NLS-1$
+ sb.append(indent).append(("<message>")).append(message).append(
+ ("</message>")).append(lineSeperator);
+ sb.append(indent).append(("<key>")).append(pattern).append(
+ ("</key>")).append(lineSeperator);
+ sb.append(indent).append(("<catalog>")).append(
+ r.getResourceBundleName()).append(("</catalog>"))
.append(lineSeperator);
}
- } else if(null != pattern){
- sb.append(indent).append(("<message>")).append(pattern).append( //$NON-NLS-1$
- ("</message>")).append(lineSeperator); //$NON-NLS-1$
- } else{
- sb.append(indent).append(("<message/>")); //$NON-NLS-1$
+ } else if (null != pattern) {
+ sb.append(indent).append(("<message>")).append(pattern).append(
+ ("</message>")).append(lineSeperator);
+ } else {
+ sb.append(indent).append(("<message/>"));
}
}
+ @SuppressWarnings("nls")
private void formatThrowable(LogRecord r, StringBuilder sb) {
Throwable t;
if ((t = r.getThrown()) != null) {
- sb.append(indent).append("<exception>").append(lineSeperator); //$NON-NLS-1$
- sb.append(indent).append(indent).append("<message>").append( //$NON-NLS-1$
- t.toString()).append("</message>").append(lineSeperator); //$NON-NLS-1$
- //format throwable's stack trace
+ sb.append(indent).append("<exception>").append(lineSeperator);
+ sb.append(indent).append(indent).append("<message>").append(
+ t.toString()).append("</message>").append(lineSeperator);
+ // format throwable's stack trace
StackTraceElement[] elements = t.getStackTrace();
for (StackTraceElement e : elements) {
- sb.append(indent).append(indent).append("<frame>").append( //$NON-NLS-1$
+ sb.append(indent).append(indent).append("<frame>").append(
lineSeperator);
sb.append(indent).append(indent).append(indent).append(
- "<class>").append(e.getClassName()).append("</class>") //$NON-NLS-1$//$NON-NLS-2$
+ "<class>").append(e.getClassName()).append("</class>")
.append(lineSeperator);
sb.append(indent).append(indent).append(indent).append(
- "<method>").append(e.getMethodName()).append( //$NON-NLS-1$
- "</method>").append(lineSeperator); //$NON-NLS-1$
+ "<method>").append(e.getMethodName()).append(
+ "</method>").append(lineSeperator);
sb.append(indent).append(indent).append(indent)
- .append("<line>").append(e.getLineNumber()).append( //$NON-NLS-1$
- "</line>").append(lineSeperator); //$NON-NLS-1$
- sb.append(indent).append(indent).append("</frame>").append( //$NON-NLS-1$
+ .append("<line>").append(e.getLineNumber()).append(
+ "</line>").append(lineSeperator);
+ sb.append(indent).append(indent).append("</frame>").append(
lineSeperator);
}
- sb.append(indent).append("</exception>").append(lineSeperator); //$NON-NLS-1$
+ sb.append(indent).append("</exception>").append(lineSeperator);
}
}
@@ -168,54 +166,48 @@ public class XMLFormatter extends Formatter {
* Returns the header string for a set of log records formatted as XML
* strings, using the output handler's encoding if it is defined, otherwise
* using the default platform encoding.
- *
+ *
* @param h
* the output handler, may be {@code null}.
* @return the header string for log records formatted as XML strings.
- * @since Android 1.0
*/
+ @SuppressWarnings("nls")
@Override
public String getHead(Handler h) {
String encoding = null;
- if(null != h) {
+ if (null != h) {
encoding = h.getEncoding();
}
if (null == encoding) {
- encoding = getSystemProperty("file.encoding"); //$NON-NLS-1$
+ encoding = getSystemProperty("file.encoding");
}
StringBuilder sb = new StringBuilder();
- sb.append("<?xml version=\"1.0\" encoding=\"").append(encoding).append( //$NON-NLS-1$
- "\" standalone=\"no\"?>").append(lineSeperator); //$NON-NLS-1$
- sb.append("<!DOCTYPE log SYSTEM \"logger.dtd\">").append(lineSeperator); //$NON-NLS-1$
- sb.append(("<log>")); //$NON-NLS-1$
+ sb.append("<?xml version=\"1.0\" encoding=\"").append(encoding).append(
+ "\" standalone=\"no\"?>").append(lineSeperator);
+ sb.append("<!DOCTYPE log SYSTEM \"logger.dtd\">").append(lineSeperator);
+ sb.append(("<log>"));
return sb.toString();
}
/**
* Returns the tail string for a set of log records formatted as XML
* strings.
- *
+ *
* @param h
* the output handler, may be {@code null}.
* @return the tail string for log records formatted as XML strings.
- * @since Android 1.0
*/
@Override
- @SuppressWarnings("unused")
public String getTail(Handler h) {
return "</log>"; //$NON-NLS-1$
}
- //use privilege code to get system property
+ // use privilege code to get system property
private static String getSystemProperty(final String key) {
- return AccessController.doPrivileged(
- new PrivilegedAction<String>() {
+ return AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return System.getProperty(key);
}
});
}
-
}
-
-
diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
index 3a06078..f2bd62d 100644
--- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
+++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
@@ -29,6 +29,8 @@ import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.LoggingPermission;
+import java.io.File;
+import java.io.FileInputStream;
import junit.framework.TestCase;
@@ -4628,6 +4630,26 @@ public class LoggerTest extends TestCase {
}
}
+ /*
+ * test initHandler
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "initHandler",
+ args = {}
+ )
+ public void test_initHandler() throws Exception {
+ File logProps = new File(LOGGING_CONFIG_FILE);
+ LogManager lm = LogManager.getLogManager();
+ lm.readConfiguration(new FileInputStream(logProps));
+
+ Logger log = Logger.getLogger("");
+ // can log properly
+ Handler[] handlers = log.getHandlers();
+ assertEquals(2, handlers.length);
+ }
+
/*
* A mock logger, used to test the protected constructors and fields.
diff --git a/logging/src/test/resources/config/java/util/logging/logging.config b/logging/src/test/resources/config/java/util/logging/logging.config
index f4c5146..6e7394b 100644
--- a/logging/src/test/resources/config/java/util/logging/logging.config
+++ b/logging/src/test/resources/config/java/util/logging/logging.config
@@ -1,3 +1,3 @@
-handlers=org.apache.harmony.logging.tests.java.util.logging.LogManagerTest$MockHandler java.util.logging.ConsoleHandler
+handlers=org.apache.harmony.logging.tests.java.util.logging.LogManagerTest$MockHandler , java.util.logging.ConsoleHandler
.level=ALL
org.apache.harmony.logging.tests.java.util.logging.LogManagerTest$MockHandler.level=OFF \ No newline at end of file