FileDocCategorySizeDatePackage
Level.javaAPI DocAndroid 1.5 API11906Wed May 06 22:41:04 BST 2009java.util.logging

Level

public class Level extends Object implements Serializable
{@code Level} objects are used to indicate the level of logging. There are a set of predefined logging levels, each associated with an integer value. Enabling a certain logging level also enables all logging levels with larger values.

The predefined levels in ascending order are FINEST, FINER, FINE, CONFIG, 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.

since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private static final List
levels
public static final Level
OFF
The OFF level provides no logging messages.
public static final Level
SEVERE
The SEVERE level provides severe failure messages.
public static final Level
WARNING
The WARNING level provides warnings.
public static final Level
INFO
The INFO level provides informative messages.
public static final Level
CONFIG
The CONFIG level provides static configuration messages.
public static final Level
FINE
The FINE level provides tracing messages.
public static final Level
FINER
The FINER level provides more detailed tracing messages.
public static final Level
FINEST
The FINEST level provides highly detailed tracing messages.
public static final Level
ALL
The ALL level provides all logging messages.
private final String
name
The name of this Level.
private final int
value
The integer value indicating the level.
private final String
resourceBundleName
The name of the resource bundle used to localize the level name.
private transient ResourceBundle
rb
The resource bundle associated with this level, used to localize the level name.
Constructors Summary
protected Level(String name, int level)
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

        this(name, level, null);
    
protected Level(String name, int level, String resourceBundleName)
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 an integer value indicating the level.
param
resourceBundleName the name of the resource bundle to use.
throws
NullPointerException if {@code name} is {@code null}.
since
Android 1.0

        if (name == null) {
            // logging.1C=The 'name' parameter is null.
            throw new NullPointerException(Messages.getString("logging.1C")); //$NON-NLS-1$
        }
        this.name = name;
        this.value = level;
        this.resourceBundleName = resourceBundleName;
        if (resourceBundleName != null) {
            try {
                rb = ResourceBundle.getBundle(resourceBundleName,
                        // BEGIN android-changed
                        Locale.getDefault(), VMStack.getCallingClassLoader());
                        // BEGIN android-changed
            } catch (MissingResourceException e) {
                rb = null;
            }
        }
        synchronized (levels) {
            levels.add(this);
        }
    
Methods Summary
public booleanequals(java.lang.Object o)
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

        if (this == o) {
            return true;
        }

        if (!(o instanceof Level)) {
            return false;
        }

        return ((Level) o).intValue() == this.value;
    
public java.lang.StringgetLocalizedName()
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

        if (rb == null) {
            return name;
        }

        try {
            return rb.getString(name);
        } catch (MissingResourceException e) {
            return name;
        }
    
public java.lang.StringgetName()
Gets the name of this level.

return
this level's name.
since
Android 1.0

        return this.name;
    
public java.lang.StringgetResourceBundleName()
Gets the name of the resource bundle associated with this level.

return
the name of this level's resource bundle.
since
Android 1.0

        return this.resourceBundleName;
    
public inthashCode()
Returns the hash code of this {@code Level} object.

return
this level's hash code.
since
Android 1.0

        return this.value;
    
public final intintValue()
Gets the integer value indicating this level.

return
this level's integer value.
since
Android 1.0

        return this.value;
    
public static java.util.logging.Levelparse(java.lang.String name)
Parses a level name into a {@code Level} object.

param
name the name of the desired {@code level}, which cannot be {@code null}.
return
the level with the specified name.
throws
NullPointerException if {@code name} is {@code null}.
throws
IllegalArgumentException if {@code name} is not valid.
since
Android 1.0

 //$NON-NLS-1$

                                                                                                         
           
        // 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$
        }

        boolean isNameAnInt;
        int nameAsInt;
        try {
            nameAsInt = Integer.parseInt(name);
            isNameAnInt = true;
        } catch (NumberFormatException e) {
            nameAsInt = 0;
            isNameAnInt = false;
        }

        synchronized (levels) {
            for (Level level : levels) {
                if (name.equals(level.getName())) {
                    return level;
                }
            }

            if (isNameAnInt) {
                /*
                 * 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()) {
                        return level;
                    }
                }
            }
        }

        if (!isNameAnInt) {
            // logging.1D=Cannot parse this name: {0}
            throw new IllegalArgumentException(Messages.getString("logging.1D", name)); //$NON-NLS-1$
        }

        return new Level(name, nameAsInt);
    
private voidreadObject(java.io.ObjectInputStream in)
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.

        in.defaultReadObject();
        if (resourceBundleName != null) {
            try {
                rb = ResourceBundle.getBundle(resourceBundleName);
            } catch (MissingResourceException e) {
                rb = null;
            }
        }
    
private java.lang.ObjectreadResolve()

Serialization helper method to maintain singletons and add any new levels.

return
the resolved instance.

        synchronized (levels) {
            for (Level level : levels) {
                if (value != level.value) {
                    continue;
                }
                if (!name.equals(name)) {
                    continue;
                }
                if (resourceBundleName == level.resourceBundleName) {
                    return level;
                } else if (resourceBundleName != null
                        && resourceBundleName.equals(level.resourceBundleName)) {
                    return level;
                }
            }
            // This is a new value, so add it.
            levels.add(this);
            return this;
        }
    
public final java.lang.StringtoString()
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

        return this.name;