FileDocCategorySizeDatePackage
LoggerFactoryJDK14.javaAPI DocGlassfish v2 API10263Fri May 04 22:35:24 BST 2007com.sun.jdo.spi.persistence.utility.logging

LoggerFactoryJDK14

public class LoggerFactoryJDK14 extends AbstractLoggerFactory
author
Craig Russell
version
1.0

Fields Summary
private static final ResourceBundle
_messages
I18N message handler for this class
Constructors Summary
public LoggerFactoryJDK14()
Creates new LoggerFactory

    
Methods Summary
protected voidconfigureFileHandler(LoggerJDK14 logger)
This method throws SecurityException if a security manager exists and if the caller does not have LoggingPermission("control")) or the calling code is not placed in the doPrivileged() block.

        String name = logger.getName();
        String baseName = name + ".FileHandler"; //NOI18N
        LogManager logManager = LogManager.getLogManager();
        
        String pattern = logManager.getProperty(baseName + ".pattern"); //NOI18N
        if(pattern != null) {
            //If pattern != null, create and attach a FileHandler to logger. 
            //Look various properties . If not found, fall back to 
            //defaults
            
            int defaultLimit = 0;
            String limit = logManager.getProperty(baseName + ".limit"); //NOI18N
            if(limit != null) {
                try {
                    defaultLimit = Integer.parseInt(limit);
                    if(defaultLimit < 0)
                        defaultLimit = 0;
                }
                catch (NumberFormatException e) {
                }
            }

            int defaultCount = 1;
            String count = logManager.getProperty(baseName + ".count"); //NOI18N
            if(count != null) {
                try {
                    defaultCount = Integer.parseInt(count);
                    if(defaultCount < 1)
                        defaultCount = 1;
                }
                catch (NumberFormatException e) {
                }
            }
            
            boolean defaultAppend = false;
            String append = logManager.getProperty(baseName + ".append"); //NOI18N
            if(append != null) {
                defaultAppend = Boolean.valueOf(append).booleanValue();
            }
            
            FileHandler fileHandler = null;
            try {
                fileHandler = new FileHandler(pattern, defaultLimit,
                            defaultCount, defaultAppend);
            }
            catch(Exception e) {
                MessageFormat messageFormat = new MessageFormat( getMessages().getString(
                    "errorlogger.filehandler.initialize.exception")); //NOI18N

                getErrorLogger().log(Logger.WARNING, 
                    messageFormat.format(new String[]{name}), e);
            }

            if(fileHandler != null) {
                //Initialize various attributes for the new fileHandler
                //--Level
                String level = logManager.getProperty(baseName + ".level"); //NOI18N
                if (level != null) {
                    try {
                        fileHandler.setLevel(Level.parse(level) );
                    }
                    catch(IllegalArgumentException e) {
                    }
                }

                //--Formatter
                Formatter defaultFormatter = null;
                //Initialize various attributes for the new fileHandler
                String formatter = logManager.getProperty(baseName + ".formatter"); //NOI18N
                if(formatter != null) {
                    try {
                        Class clz = ClassLoader.getSystemClassLoader().loadClass(formatter);
                            defaultFormatter = (Formatter) clz.newInstance();
                    } catch (Exception e) {
                      // We got one of a variety of exceptions in creating the
                      // class or creating an instance.
                      // Drop through.
                      MessageFormat messageFormat = new MessageFormat(
                         getMessages().getString("errorlogger.formatter.initialize.exception"));

                      getErrorLogger().log(Logger.WARNING, messageFormat.format(new String[]{name}), e);
                    }
                
                }
                
                if (defaultFormatter == null) {
                    defaultFormatter = new SimpleFormatter();
                }
                
                try {
                   fileHandler.setFormatter(defaultFormatter);
                }
                catch(IllegalArgumentException e) {
                }

                logger.addHandler(fileHandler);

            }   //if(fileHandler != null) 
            
        }   //if(pattern != null) 

    
protected LoggercreateLogger(java.lang.String absoluteLoggerName, java.lang.String bundleName, java.lang.ClassLoader loader)
Create a new Logger. create a logger for the named component. The bundle name and class loader are passed to allow the implementation to properly find and construct the internationalization bundle. This operation is executed as a privileged action to allow permission access for the following operations: LogManager.getLogManager().addLogger - this might do checkAccess. new FileHandler FileHandler.setLevel FileHandler.setFormatter Logger.addHandler

param
absoluteLoggerName the absolute name of this logger
param
bundleName the fully qualified name of the resource bundle
param
loader the class loader used to load the resource bundle, or null
return
the logger

        return (Logger) AccessController.doPrivileged ( 
            new PrivilegedAction () { 
                public Object run () { 
                    LoggerJDK14 logger = null;
                    ClassLoader pushed = Thread.currentThread().getContextClassLoader();
                    if(loader!=null) {
                        setContextClassLoader (loader);
                    }
                    try {
                        logger = createLogger(absoluteLoggerName, bundleName);
                        LogManager.getLogManager().addLogger(logger);
                        configureFileHandler(logger);

                        return logger;
                    } catch (Exception ex) {
                          MessageFormat messageFormat = new MessageFormat(
                              getMessages().getString("errorlogger.create.exception"));

                          getErrorLogger().log(Logger.SEVERE, messageFormat.format(
                              new String[]{absoluteLoggerName}), ex);
                    } finally {
                        setContextClassLoader (pushed);
                    }

                    return logger;
                } 
            } 
        );
    
protected LoggerJDK14createLogger(java.lang.String absoluteLoggerName, java.lang.String bundleName)

            LoggerJDK14 result = new LoggerJDK14(absoluteLoggerName, bundleName);
            return result;
    
protected LoggerJDK14findLogger(java.lang.String absoluteLoggerName)

        return (LoggerJDK14)
        LogManager.getLogManager().getLogger(absoluteLoggerName);
    
protected static java.util.ResourceBundlegetMessages()
Get the message bundle for the AbstractLogger itself.


                 
          return _messages; 
protected voidsetContextClassLoader(java.lang.ClassLoader loader)
This method throws SecurityException if a security manager exists and if the caller does not have LoggingPermission("control")) or the calling code is not placed in the doPrivileged() block.

        if (loader != null) {
            Thread.currentThread().setContextClassLoader (loader);
        }