On 9/4/06, Paulex Yang wrote:
Stepan Mishura wrote:
> On 9/1/06, Paulex Yang wrote:
>>
>> Stepan Mishura wrote:
>> > Hi Andrew,
>> >
>> > I've just looked into static initialization block and then to the
>> > spec. for
>> > LogManager class.
>> > My impression is that Harmony implementation doesn't follow the spec.
>> >
>> > The spec. says: "At startup the LogManager class is located using
>> the '
>> > java.util.logging.manager' system property.By default, the LogManager
>> > reads
>> > its initial configuration from a properties file
>> > "lib/logging.properties" in
>> > the JRE directory...."
>> Stepan,
>>
>> I think the meaning of "By default" is debatable. Actually the spec
>> looks like this:
>>
>> "At startup the LogManager class is located using the
>> java.util.logging.manager system property.
>>
>> By default, the LogManager reads its initial configuration from a
>> properties file "lib/logging.properties" in the JRE directory. If you
>> edit that property file you can change the default logging configuration
>> for all uses of that JRE.
>>
>> In addition, the LogManager uses two optional system properties that
>> allow more control over reading the initial configuration:
>>
>>    * "java.util.logging.config.class"
>>    * "java.util.logging.config.file"...
>>
>> "
>>
>> So I consider the "By default" doesn't necessarily means default case
>> without " java.util.logging.manager" property, but means the default case
>> without "java.util.logging.config.class/file" properties.
>>
>> A simple test on RI of specifying a customized MockLogManager by
>> "j.u.l.manager" property shows the default "lib/logging.properties" does
>> affect the behavior of the customized LogManager, say the root logger's
>> level, etc.
>
>
> Do you mean that RI resets the root logger's level of customized
> LogManager
> to default value from "lib/logging.properties"?
Yes, so I think customized LogManager also needs to initialize itself in
same procedure as j.u.l.LogManager.
 
 
Hi Paulex,
 
I've implemented custom LogManager (see attachment): it sets value for root logger's level different from default value(INFO). According to my test (see attachment) RI doesn't change level of root logger.
 
The test prints the following:
$java -classpath . MyTest
INFO
$java -classpath . -Djava.util.logging.manager=CustomLogManager MyTest
SEVERE
 
Did I missed something?
 
Thanks,
Stepan.

------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class CustomLogManager extends LogManager {

    private Hashtable loggers;

    public CustomLogManager() {
    }

    public String getProperty(String p) {
        return null;
    }

    public synchronized boolean addLogger(Logger logger) {
        if (loggers.contains(logger)) {
            return false;
        }
        loggers.put(logger.getName(), logger);
        return true;
    }

    public synchronized Logger getLogger(String logger) {
        return (Logger) loggers.get(logger);
    }

    public synchronized Enumeration getLoggerNames() {
        return loggers.keys();
    }

    public void addPropertyChangeListener(PropertyChangeListener arg0)
            throws SecurityException {
    }

    public void checkAccess() throws SecurityException {
    }

    public void readConfiguration() throws IOException, SecurityException {

        loggers = new Hashtable();

        // set root logger
        Logger root = new Logger("", null) {
            {
                setLevel(Level.SEVERE);
            }
        };
        loggers.put("", root);
    }

    public void readConfiguration(InputStream in) throws IOException,
            SecurityException {
    }

    public void removePropertyChangeListener(PropertyChangeListener prop)
            throws SecurityException {
    }

    public void reset() throws SecurityException {
    }
}
import java.util.logging.LogManager;

public class MyTest {

    public static void main(String[] args) {
        System.out.println(LogManager.getLogManager().getLogger("").getLevel());
    }
}
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to