You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/08/28 23:35:06 UTC
svn commit: r570577 -
/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/
Author: tellison
Date: Tue Aug 28 14:35:05 2007
New Revision: 570577
URL: http://svn.apache.org/viewvc?rev=570577&view=rev
Log:
Formatting changes.
Modified:
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Formatter.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Handler.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingMXBean.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingPermission.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java Tue Aug 28 14:35:05 2007
@@ -42,7 +42,6 @@
* <p>
* This class is not thread-safe.
* </p>
- *
*/
public class ConsoleHandler extends StreamHandler {
@@ -65,12 +64,12 @@
/**
* Logs a record if necessary. A flush operation will be done.
*
- * @param record the log record to be logged
+ * @param record
+ * the log record to be logged
*/
@Override
public void publish(LogRecord record) {
super.publish(record);
super.flush();
-
}
}
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java Tue Aug 28 14:35:05 2007
@@ -20,12 +20,10 @@
import org.apache.harmony.logging.internal.nls.Messages;
/**
- * <p>
* An error reporting facility for {@link Handler} implementations to record any
* error that may happen during logging. <code>Handlers</code> should report
* errors to an <code>ErrorManager</code>, instead of throwing exceptions,
* which would interfere with the log issuer's execution.
- * </p>
*/
public class ErrorManager {
@@ -79,12 +77,10 @@
}
/**
- * <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</code>.
@@ -103,7 +99,7 @@
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$
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java Tue Aug 28 14:35:05 2007
@@ -228,21 +228,22 @@
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;
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java Tue Aug 28 14:35:05 2007
@@ -18,15 +18,16 @@
package java.util.logging;
/**
- * <p>A Filter provides a mechanism for exercising fine-grained control over
- * what records get logged.</p>
+ * A Filter provides a mechanism for exercising fine-grained control over what
+ * records get logged.
*/
public interface Filter {
/**
- * <p>Checks the {@link LogRecord} to determine if it should be logged.</p>
+ * Checks the {@link LogRecord} to determine if it should be logged.
*
- * @param record The {@link LogRecord} to be checked.
+ * @param record
+ * The {@link LogRecord} to be checked.
* @return <code>true</code> if the supplied log record needs to be
* logged, otherwise <code>false</code>
*/
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Formatter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Formatter.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Formatter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Formatter.java Tue Aug 28 14:35:05 2007
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.text.MessageFormat;
@@ -26,16 +25,9 @@
* objects into a string representation. Head and tail strings are sometime used
* to wrap a set of records. The <code>getHead</code> and <code>getTail</code>
* methods are presented for this purpose.
- *
*/
public abstract class Formatter {
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
-
/**
* Constructs a <code>Formatter</code> object.
*/
@@ -43,12 +35,6 @@
super();
}
- /*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
-
/**
* Formats a <code>LogRecord</code> object into a string representation.
* The resulted string is usually localized and includes the message field
@@ -128,6 +114,4 @@
public String getTail(Handler h) {
return ""; //$NON-NLS-1$
}
-
}
-
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Handler.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Handler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Handler.java Tue Aug 28 14:35:05 2007
@@ -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,23 +28,11 @@
* A <code>Handler</code> 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</code>.
- *
*/
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;
@@ -64,12 +51,6 @@
// class name, used for property reading
private String prefix;
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
-
/**
* Constructs a <code>Handler</code> object with a default error manager,
* the default encoding, and the default logging level
@@ -84,12 +65,6 @@
this.prefix = this.getClass().getName();
}
- /*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
-
// get a instance from given class name, using Class.forName()
private Object getDefaultInstance(String className) {
Object result = null;
@@ -99,7 +74,7 @@
try {
result = Class.forName(className).newInstance();
} catch (Exception e) {
- //ignore
+ // ignore
}
return result;
}
@@ -107,7 +82,8 @@
// 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();
@@ -123,7 +99,8 @@
// 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);
@@ -138,7 +115,7 @@
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 {
@@ -151,7 +128,7 @@
filter = (Filter) getDefaultInstance(defaultFilter);
}
- //set level
+ // set level
String levelName = manager.getProperty(prefix + ".level"); //$NON-NLS-1$
if (null != levelName) {
try {
@@ -164,7 +141,7 @@
level = Level.parse(defaultLevel);
}
- //set formatter
+ // set formatter
final String formatterName = manager.getProperty(prefix + ".formatter"); //$NON-NLS-1$
if (null != formatterName) {
try {
@@ -177,7 +154,7 @@
formatter = (Formatter) getDefaultInstance(defaultFormatter);
}
- //set encoding
+ // set encoding
final String encodingName = manager.getProperty(prefix + ".encoding"); //$NON-NLS-1$
try {
internalSetEncoding(encodingName);
@@ -417,4 +394,3 @@
this.level = newLevel;
}
}
-
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java Tue Aug 28 14:35:05 2007
@@ -26,8 +26,8 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import org.apache.harmony.logging.internal.nls.Messages;
import org.apache.harmony.kernel.vm.VM;
+import org.apache.harmony.logging.internal.nls.Messages;
/**
* <code>Level</code> objects are used to indicate the level of logging. There
@@ -40,7 +40,6 @@
* ALL and OFF. ALL indicates logging all messages, and OFF indicates logging no
* messages.
* </p>
- *
*/
public class Level implements Serializable {
@@ -129,8 +128,8 @@
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()) {
@@ -142,7 +141,8 @@
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);
@@ -179,9 +179,12 @@
* Constructs an instance of <code>Level</code> taking the supplied name
* and level value.
*
- * @param name name of the level
- * @param level an integer value indicating the level
- * @throws NullPointerException if <code>name</code> is <code>null</code>.
+ * @param name
+ * name of the level
+ * @param level
+ * an integer value indicating the level
+ * @throws NullPointerException
+ * if <code>name</code> is <code>null</code>.
*/
protected Level(String name, int level) {
this(name, level, null);
@@ -191,10 +194,14 @@
* Constructs an instance of <code>Level</code> taking the supplied name
* and level value.
*
- * @param name name of the level
- * @param level an integer value indicating the level
- * @param resourceBundleName the name of the resource bundle to use
- * @throws NullPointerException if <code>name</code> is <code>null</code>.
+ * @param name
+ * name of the level
+ * @param level
+ * an integer value indicating the level
+ * @param resourceBundleName
+ * the name of the resource bundle to use
+ * @throws NullPointerException
+ * if <code>name</code> is <code>null</code>.
*/
protected Level(String name, int level, String resourceBundleName) {
if (name == null) {
@@ -206,8 +213,8 @@
this.resourceBundleName = resourceBundleName;
if (resourceBundleName != null) {
try {
- rb = ResourceBundle.getBundle(resourceBundleName,
- Locale.getDefault(), VM.callerClassLoader());
+ rb = ResourceBundle.getBundle(resourceBundleName, Locale
+ .getDefault(), VM.callerClassLoader());
} catch (MissingResourceException e) {
rb = null;
}
@@ -247,10 +254,8 @@
}
/**
- * <p>
* Serialization helper method to maintain singletons and add any new
* levels.
- * </p>
*
* @return The resolved instance.
*/
@@ -277,12 +282,17 @@
}
/**
- * <p>Serialization helper to setup transient resource bundle instance.</p>
- * @param in The input stream to read the instance data from.
- * @throws IOException if an IO error occurs.
- * @throws ClassNotFoundException if a class is not found.
+ * Serialization helper to setup transient resource bundle instance.
+ *
+ * @param in
+ * The input stream to read the instance data from.
+ * @throws IOException
+ * if an IO error occurs.
+ * @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 {
@@ -316,7 +326,8 @@
* Compares two <code>Level</code> objects for equality. They are
* considered to be equal if they have the same value.
*
- * @param o the other object to be compared with
+ * @param o
+ * the other object to be compared with
* @return <code>true</code> if this object equals to the supplied object,
* otherwise <code>false</code>
*/
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java Tue Aug 28 14:35:05 2007
@@ -24,6 +24,8 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.management.ManagementFactory;
+import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
@@ -33,12 +35,10 @@
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
-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.ObjectName;
import org.apache.harmony.logging.internal.nls.Messages;
@@ -123,15 +123,14 @@
*/
public class LogManager {
/*
- * -------------------------------------------------------------------
- * Class variables
+ * ------------------------------------------------------------------- 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(
@@ -139,12 +138,13 @@
// the singleton instance
static LogManager manager;
-
+
/**
- * <p>The String value of the {@link LoggingMXBean}'s ObjectName.</p>
+ * <p>
+ * The String value of the {@link LoggingMXBean}'s ObjectName.
+ * </p>
*/
- 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</code> instance
@@ -154,40 +154,35 @@
public static LoggingMXBean getLoggingMXBean() {
try {
ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME);
- MBeanServer platformBeanServer =
- ManagementFactory.getPlatformMBeanServer();
+ 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"));
+ 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");
+ Method giMethod = lmxbc.getDeclaredMethod("getInstance"); //$NON-NLS-1$
giMethod.setAccessible(true);
- LoggingMXBean lmxb = (LoggingMXBean)
- giMethod.invoke(null, new Object[] {});
+ LoggingMXBean lmxb = (LoggingMXBean) giMethod.invoke(null,
+ new Object[] {});
return lmxb;
} catch (Exception e) {
- //TODO
- //e.printStackTrace();
+ // TODO
+ // e.printStackTrace();
}
// logging.22=Exception occurred while getting the logging MX bean.
throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$
}
- /*
- * -------------------------------------------------------------------
- * 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
@@ -196,44 +191,38 @@
// 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$
-
- if (null != className) {
- manager = (LogManager) getInstanceByClass(className);
- }
- if (null == manager) {
- manager = new LogManager();
- }
-
- // read configuration
- try {
- manager.readConfiguration();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ // init LogManager singleton instance
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ String className = System
+ .getProperty("java.util.logging.manager"); //$NON-NLS-1$
- // if global logger has been initialized, set root as its parent
+ if (null != className) {
+ manager = (LogManager) getInstanceByClass(className);
+ }
+ if (null == manager) {
+ manager = new LogManager();
+ }
+
+ // read configuration
+ try {
+ manager.readConfiguration();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // if global logger has been initialized, set root as its parent
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;
- }
- });
- }
+ }
+ });
+ }
/**
* Default constructor. This is not public because there should be only one
@@ -261,11 +250,6 @@
}
/*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
- /*
* Package private utilities Returns the line separator of the underlying
* OS.
*/
@@ -319,7 +303,6 @@
return true;
}
-
private void addToFamilyTree(Logger logger, String name) {
Logger parent = null;
// find parent
@@ -331,8 +314,8 @@
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;
@@ -343,7 +326,7 @@
}
// find children
- //TODO: performance can be improved here?
+ // TODO: performance can be improved here?
Collection<Logger> allLoggers = loggers.values();
for (final Logger child : allLoggers) {
Logger oldParent = child.getParent();
@@ -358,7 +341,7 @@
}
});
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);
}
}
@@ -406,8 +389,8 @@
}
/**
- * Re-initialize the properties and configuration. The initialization process
- * is same as the <code>LogManager</code> instantiation.
+ * Re-initialize the properties and configuration. The initialization
+ * process is same as the <code>LogManager</code> instantiation.
* <p>
* A <code>PropertyChangeEvent</code> must be fired.
* </p>
@@ -421,19 +404,20 @@
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;
@@ -468,13 +452,12 @@
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;
}
@@ -487,7 +470,7 @@
throws IOException {
reset();
props.load(ins);
-
+
// parse property "config" and apply setting
String configs = props.getProperty("config"); //$NON-NLS-1$
if (null != configs) {
@@ -497,20 +480,18 @@
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</code>
@@ -547,10 +528,10 @@
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();
}
}
@@ -571,7 +552,7 @@
* not have the required permissions to perform this action
*/
public void addPropertyChangeListener(PropertyChangeListener l) {
- if(l == null){
+ if (l == null) {
throw new NullPointerException();
}
checkAccess();
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java Tue Aug 28 14:35:05 2007
@@ -41,7 +41,6 @@
* they expect to use them after passing the <code>LogRecord</code> object to
* another thread or transmitting it over RMI.
* </p>
- *
*/
public class LogRecord implements Serializable {
@@ -353,7 +352,7 @@
}
/*
- * Init the sourceClass and sourceMethod fields.
+ * Init the sourceClass and sourceMethod fields.
*/
private void initSource() {
if (!sourceInited) {
@@ -366,8 +365,9 @@
break FINDLOG;
}
}
- while(++i<elements.length && elements[i].getClassName().equals(current)) {
- // do nothing
+ while (++i < elements.length
+ && elements[i].getClassName().equals(current)) {
+ // do nothing
}
if (i < elements.length) {
this.sourceClassName = elements[i].getClassName();
@@ -474,12 +474,12 @@
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$
}
-
+
int length = in.readInt();
if (length >= 0) {
parameters = new Object[length];
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java Tue Aug 28 14:35:05 2007
@@ -24,7 +24,6 @@
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import java.util.StringTokenizer;
import org.apache.harmony.logging.internal.nls.Messages;
@@ -113,17 +112,11 @@
private boolean isNamed;
private List<Logger> childs;
-
+
private LogManager manager;
private boolean handlerInited;
- /*
- * -------------------------------------------------------------------
- * Constructors
- * -------------------------------------------------------------------
- */
-
/**
* Constructs a <code>Logger</code> object with the supplied name and
* resource bundle name.
@@ -153,24 +146,24 @@
// 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();
}
@@ -179,7 +172,7 @@
}
}
- //-- 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
@@ -188,12 +181,6 @@
}
}
- /*
- * -------------------------------------------------------------------
- * Methods
- * -------------------------------------------------------------------
- */
-
/**
* Load the specified resource bundle, use privileged code.
*
@@ -205,8 +192,8 @@
*/
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();
}
@@ -220,12 +207,11 @@
}
}
// 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
@@ -246,8 +232,8 @@
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();
}
@@ -263,17 +249,17 @@
}
// 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);
}
/**
* Gets an anonymous logger to use internally in a thread. Anonymous loggers
* are not registered in the log manager's namespace. No security checks
- * will be performed when updating an anonymous logger's control settings
- * so that they can be used in applets.
+ * will be performed when updating an anonymous logger's control settings so
+ * that they can be used in applets.
* <p>
- * Anonymous loggers' parent is set to be the root logger. This enables
- * them to inherit default logging level and handlers from the root logger.
+ * Anonymous loggers' parent is set to be the root logger. This enables them
+ * to inherit default logging level and handlers from the root logger.
* </p>
*
* @return a new instance of anonymous logger
@@ -285,11 +271,11 @@
/**
* Gets an anonymous logger to use internally in a thread. Anonymous loggers
* are not registered in the log manager's namespace. No security checks
- * will be performed when updating an anonymous logger's control settings
- * so that they can be used in applets.
+ * will be performed when updating an anonymous logger's control settings so
+ * that they can be used in applets.
* <p>
- * Anonymous loggers' parent is set to be the root logger. This enables
- * them to inherit default logging level and handlers from the root logger.
+ * Anonymous loggers' parent is set to be the root logger. This enables them
+ * to inherit default logging level and handlers from the root logger.
* </p>
*
* @param resourceBundleName
@@ -306,33 +292,30 @@
}
/*
- * Check whether the same resource bundle has been specified.
- * Synchronize to ensure the consistency between resource bundle
- * and its name.
+ * Check whether the same resource bundle has been specified. Synchronize to
+ * ensure the consistency between resource bundle and its name.
*/
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()));
}
}
}
@@ -412,18 +395,18 @@
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) {
if (handlers == null) {
@@ -438,10 +421,10 @@
if (null == handlerStr) {
return;
}
- String[] strs = handlerStr.split(",|\\s");
+ String[] strs = handlerStr.split(",|\\s"); //$NON-NLS-1$
for (int i = 0; i < strs.length; i++) {
String handlerName = strs[i];
- if (handlerName.equals("")){
+ if (handlerName.equals("")) { //$NON-NLS-1$
continue;
}
Handler handler = (Handler) LogManager
@@ -466,7 +449,7 @@
*/
public Handler[] getHandlers() {
initHandler();
- synchronized(this){
+ synchronized (this) {
return handlers.toArray(new Handler[handlers.size()]);
}
}
@@ -490,7 +473,7 @@
return;
}
initHandler();
- synchronized(this){
+ synchronized (this) {
this.handlers.remove(handler);
}
}
@@ -590,15 +573,16 @@
/**
* Sets the parent of this logger in the namespace. This method should
- * usually be used by the <code>LogManager</code> object only. This
- * method does not check security.
+ * usually be used by the <code>LogManager</code> object only. This method
+ * does not check security.
*
* @param newParent
* the parent logger to set
*/
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
@@ -637,7 +621,6 @@
childs.remove(child);
}
-
/**
* Gets the name of this logger.
*
@@ -669,9 +652,9 @@
}
/**
- * This method is for compatibility. Tests written to the reference
- * implementation API imply that the isLoggable() method is not called
- * directly. This behavior is important because subclass may override
+ * This method is for compatibility. Tests written to the reference
+ * implementation API imply that the isLoggable() method is not called
+ * directly. This behavior is important because subclass may override
* isLoggable() method, so that affect the result of log methods.
*/
private boolean internalIsLoggable(Level l) {
@@ -785,14 +768,14 @@
public void entering(String sourceClass, String sourceMethod,
Object[] params) {
if (internalIsLoggable(Level.FINER)) {
- String msg = "ENTRY"; //$NON-NLS-1$
- if (null != params) {
- StringBuilder msgBuffer = new StringBuilder("ENTRY"); //$NON-NLS-1$
- for (int i = 0; i < params.length; i++) {
- msgBuffer.append(" {" + i + "}"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- msg = msgBuffer.toString();
- }
+ String msg = "ENTRY"; //$NON-NLS-1$
+ if (null != params) {
+ StringBuilder msgBuffer = new StringBuilder("ENTRY"); //$NON-NLS-1$
+ for (int i = 0; i < params.length; i++) {
+ msgBuffer.append(" {" + i + "}"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ msg = msgBuffer.toString();
+ }
LogRecord record = new LogRecord(Level.FINER, msg);
record.setLoggerName(this.name);
record.setSourceClassName(sourceClass);
@@ -1084,8 +1067,7 @@
}
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) {
@@ -1375,12 +1357,12 @@
}
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
- final 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 {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@@ -1390,15 +1372,15 @@
}
});
} 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
@@ -1413,4 +1395,3 @@
handlerInited = false;
}
}
-
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingMXBean.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingMXBean.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingMXBean.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingMXBean.java Tue Aug 28 14:35:05 2007
@@ -20,10 +20,7 @@
import java.util.List;
/**
- * <p>
* The management interface for the logging sub-system.
- * </p>
- *
* <p>
* ObjectName =
* {@link LogManager#LOGGING_MXBEAN_NAME java.util.logging:type=Logging}
@@ -32,54 +29,51 @@
* @since 1.5
*/
public interface LoggingMXBean {
+
/**
- * <p>
* 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.
- * </p>
*
- * @param loggerName The name of the logger lookup.
+ * @param loggerName
+ * The name of the logger lookup.
* @return A String if the logger was found, otherwise <code>null</code>.
* @see Level#getName()
*/
String getLoggerLevel(String loggerName);
/**
- * <p>
* Gets a list of all currently registered logger's names. This is performed
* using the {@link LogManager#getLoggerNames()}.
- * </p>
*
* @return A List of String instances.
*/
List<String> getLoggerNames();
/**
- * <p>
* Gets the name of the parent logger of a logger. If the logger doesn't
* exist then <code>null</code> is returned. If the logger is the root
* logger, then an empty String is returned.
- * </p>
*
- * @param loggerName The name of the logger to lookup.
+ * @param loggerName
+ * The name of the logger to lookup.
* @return A String if the logger was found, otherwise <code>null</code>.
*/
String getParentLoggerName(String loggerName);
/**
- * <p>
* Sets the log level of a logger.
- * </p>
*
- * @param loggerName The name of the logger to set the level on, which must
- * not be <code>null</code>.
- * @param levelName The level to set on the logger, which may be
- * <code>null</code>.
- * @throws IllegalArgumentException if <code>loggerName</code> is not a
- * registered logger or if <code>levelName</code> is not null and
- * an invalid value.
- * @throws SecurityException if a security manager exists and the caller
- * doesn't have LoggingPermission("control").
+ * @param loggerName
+ * The name of the logger to set the level on, which must not be
+ * <code>null</code>.
+ * @param levelName
+ * The level to set on the logger, which may be <code>null</code>.
+ * @throws IllegalArgumentException
+ * if <code>loggerName</code> is not a registered logger or if
+ * <code>levelName</code> is not null and an invalid value.
+ * @throws SecurityException
+ * if a security manager exists and the caller doesn't have
+ * LoggingPermission("control").
* @see Level#parse(String)
*/
void setLoggerLevel(String loggerName, String levelName);
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingPermission.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingPermission.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingPermission.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LoggingPermission.java Tue Aug 28 14:35:05 2007
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.io.Serializable;
@@ -27,20 +26,12 @@
/**
* The permission required to control the logging when run with a
* <code>SecurityManager</code>.
- *
*/
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</code> object required to control
@@ -65,4 +56,3 @@
}
}
-
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java Tue Aug 28 14:35:05 2007
@@ -22,7 +22,6 @@
import org.apache.harmony.logging.internal.nls.Messages;
-
/**
* <code>MemoryHandler</code> is a <code>Handler</code> that 'remembers' a
* finite number of <code>LogRecord</code>s at a time and stores them in a
@@ -63,93 +62,96 @@
* 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</code> using
- * <code>LogManager</code> properties or default values
+ * Default constructor, construct and init a <code>MemoryHandler</code>
+ * using <code>LogManager</code> properties or default values
*/
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</code> using given target, size
- * and push level, other properties using <code>LogManager</code> properties
- * or default values
+ * Construct and init a <code>MemoryHandler</code> using given target,
+ * size and push level, other properties using <code>LogManager</code>
+ * properties or default values
*
* @param target
- * the given <code>Handler</code> to output
- * @param size the maximum number of buffered <code>LogRecord</code>
+ * the given <code>Handler</code> to output
+ * @param size
+ * the maximum number of buffered <code>LogRecord</code>
* @param pushLevel
- * the push level
+ * the push level
* @throws IllegalArgumentException
- * if size<=0
+ * if size<=0
*/
public MemoryHandler(Handler target, int size, Level pushLevel) {
if (size <= 0) {
@@ -161,16 +163,16 @@
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
+ * if security manager exists and it determines that caller does
+ * not have the required permissions to control this handler
*/
@Override
public void close() {
@@ -183,7 +185,6 @@
* Call target handler to flush any buffered output.
*
* Note that this doesn't cause this <code>MemoryHandler</code> to push.
- *
*/
@Override
public void flush() {
@@ -193,12 +194,13 @@
/**
* Put a given <code>LogRecord</code> into internal buffer.
*
- * If given record is not loggable, just return. Otherwise it is stored in
+ * If given record is not loggable, just return. Otherwise it is stored in
* the buffer. 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.
+ * 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.
+ * @param record
+ * the log record.
*/
@Override
public synchronized void publish(LogRecord record) {
@@ -225,19 +227,19 @@
}
/**
- * <p>Check if given <code>LogRecord</code> would be put into this
+ * Check if given <code>LogRecord</code> would be put into this
* <code>MemoryHandler</code>'s internal buffer.
- * </p>
* <p>
- * The given <code>LogRecord</code> is loggable if and only if it has
- * appropriate level and it pass any associated filter's check.
+ * The given <code>LogRecord</code> 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.
+ * Note that the push level is not used for this check.
* </p>
+ *
* @param record
- * the given <code>LogRecord</code>
- * @return if the given <code>LogRecord</code> should be logged
+ * the given <code>LogRecord</code>
+ * @return if the given <code>LogRecord</code> should be logged
*/
@Override
public boolean isLoggable(LogRecord record) {
@@ -245,18 +247,19 @@
}
/**
- * Triggers a push action to output all buffered records to the target handler,
- * and the target handler will publish them. Then the buffer is cleared.
+ * Triggers a push action to output all buffered records to the target
+ * handler, and the target handler will publish them. Then the buffer is
+ * cleared.
*/
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;
@@ -265,16 +268,17 @@
}
/**
- * 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</code> is put into the internal
- * 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.
+ * 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
+ * the new level to set
* @throws SecurityException
- * if security manager exists and it determines that caller
- * does not have the required permissions to control this handler
+ * if security manager exists and it determines that caller does
+ * not have the required permissions to control this handler
*/
public void setPushLevel(Level newLevel) {
manager.checkAccess();
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java Tue Aug 28 14:35:05 2007
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.io.PrintWriter;
@@ -27,7 +26,6 @@
* <code>SimpleFormatter</code> can be used to print a summary of the
* information contained in a <code>LogRecord</code> object in a human
* readable format.
- *
*/
public class SimpleFormatter extends Formatter {
/**
@@ -43,7 +41,8 @@
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()) {
@@ -56,7 +55,7 @@
t.printStackTrace(pw);
sb.append(sw.toString());
} finally {
- if(pw != null){
+ if (pw != null) {
try {
pw.close();
} catch (Exception e) {
@@ -68,4 +67,3 @@
return sb.toString();
}
}
-
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java Tue Aug 28 14:35:05 2007
@@ -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;
@@ -56,9 +55,9 @@
* <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$
@@ -154,8 +153,8 @@
try {
super.close();
if (null != this.socket) {
- this.socket.close();
- this.socket = null;
+ this.socket.close();
+ this.socket = null;
}
} catch (Exception e) {
// logging.F=Exception occurred when closing the socket handler.
@@ -175,5 +174,4 @@
super.publish(record);
super.flush();
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java Tue Aug 28 14:35:05 2007
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.io.OutputStream;
@@ -46,9 +45,9 @@
* <p>
* This class is not thread-safe.
* </p>
- *
*/
public class StreamHandler extends Handler {
+
// the output stream this handler writes to
private OutputStream os;
@@ -63,7 +62,7 @@
* does not have an associated output stream.
*/
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;
@@ -158,7 +157,6 @@
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
@@ -196,8 +194,8 @@
@Override
public void setEncoding(String encoding) throws SecurityException,
UnsupportedEncodingException {
- //flush first before set new encoding
- this.flush();
+ // flush first before set new encoding
+ this.flush();
super.setEncoding(encoding);
// renew writer only if the writer exists
if (null != this.writer) {
@@ -219,7 +217,8 @@
/**
* Closes this handler, but the underlying output stream is only closed when
- * <code>closeStream</code> is <code>true</code>. Security is not checked.
+ * <code>closeStream</code> is <code>true</code>. Security is not
+ * checked.
*
* @param closeStream
* whether to close the underlying output stream
@@ -234,8 +233,8 @@
this.writer.flush();
if (closeStream) {
this.writer.close();
- this.writer = null;
- this.os = null;
+ this.writer = null;
+ this.os = null;
}
} catch (Exception e) {
// logging.15=Exception occurred when closing the output stream.
@@ -274,7 +273,8 @@
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,7 +309,8 @@
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);
}
@@ -334,13 +335,12 @@
*/
@Override
public boolean isLoggable(LogRecord record) {
- if (null == record) {
- return false;
- }
+ if (null == record) {
+ return false;
+ }
if (null != this.os && super.isLoggable(record)) {
return true;
}
return false;
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java?rev=570577&r1=570576&r2=570577&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java Tue Aug 28 14:35:05 2007
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.util.logging;
import java.security.AccessController;
@@ -25,12 +24,12 @@
import java.util.ResourceBundle;
/**
- * Format a given <code>LogRecord</code> into string represents XML. The DTD specified in
- * Appendix A to Java Logging APIs specification is used.
- *
- * <code>XMLFormatter</code> uses given <code>Handler</code>'s encoding if has, otherwise
- * uses default platform encoding instead. However, the UTF-8 is recommended encoding.
+ * Format a given <code>LogRecord</code> into string represents XML. The DTD
+ * specified in Appendix A to Java Logging APIs specification is used.
*
+ * <code>XMLFormatter</code> uses given <code>Handler</code>'s encoding if
+ * has, otherwise uses default platform encoding instead. However, the UTF-8 is
+ * recommended encoding.
*/
public class XMLFormatter extends Formatter {
@@ -47,60 +46,64 @@
}
/**
- * Format a <code>LogRecord</code> into string which represents XML
+ * Format a <code>LogRecord</code> into string which represents XML.
*
- * @param r the given LogRecord instance to be formatted
- * @return string which represents XML
+ * @param r
+ * the given LogRecord instance to be formatted
+ * @return string which represents XML
*/
+ @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) {
@@ -113,80 +116,84 @@
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);
}
}
/**
- * Return the header string for XML, use given handler's encoding if has,
- * other wise use default platform encoding
+ * Return the header string for XML, use given handler's encoding if has,
+ * other wise use default platform encoding
*
- * @param h the given handler
+ * @param h
+ * the given handler
* @return the header string for XML
*/
+ @SuppressWarnings("nls")
@Override
public String getHead(Handler h) {
String encoding = null;
- if(null != h) {
- encoding = h.getEncoding();
+ 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();
}
/**
* Return the tail string for XML
*
- * @param h the given handler
+ * @param h
+ * the given handler
* @return the tail string for XML
*/
@Override
@@ -195,16 +202,12 @@
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);
}
});
}
-
}
-
-