src/share/classes/java/util/logging/MemoryHandler.java

Print this page




  99     // javadoc.
 100     private void configure() {
 101         LogManager manager = LogManager.getLogManager();
 102         String cname = getClass().getName();
 103 
 104         pushLevel = manager.getLevelProperty(cname +".push", Level.SEVERE);
 105         size = manager.getIntProperty(cname + ".size", DEFAULT_SIZE);
 106         if (size <= 0) {
 107             size = DEFAULT_SIZE;
 108         }
 109         setLevel(manager.getLevelProperty(cname +".level", Level.ALL));
 110         setFilter(manager.getFilterProperty(cname +".filter", null));
 111         setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));
 112     }
 113 
 114     /**
 115      * Create a <tt>MemoryHandler</tt> and configure it based on
 116      * <tt>LogManager</tt> configuration properties.
 117      */
 118     public MemoryHandler() {
 119         sealed = false;
 120         configure();
 121         sealed = true;
 122 
 123         LogManager manager = LogManager.getLogManager();
 124         String handlerName = getClass().getName();
 125         String targetName = manager.getProperty(handlerName+".target");
 126         if (targetName == null) {
 127             throw new RuntimeException("The handler " + handlerName
 128                     + " does not specify a target");
 129         }
 130         Class<?> clz;
 131         try {
 132             clz = ClassLoader.getSystemClassLoader().loadClass(targetName);
 133             target = (Handler) clz.newInstance();
 134         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
 135             throw new RuntimeException("MemoryHandler can't load handler target \"" + targetName + "\"" , e);
 136         }
 137         init();
 138     }
 139 
 140     // Initialize.  Size is a count of LogRecords.
 141     private void init() {


 147     /**
 148      * Create a <tt>MemoryHandler</tt>.
 149      * <p>
 150      * The <tt>MemoryHandler</tt> is configured based on <tt>LogManager</tt>
 151      * properties (or their default values) except that the given <tt>pushLevel</tt>
 152      * argument and buffer size argument are used.
 153      *
 154      * @param target  the Handler to which to publish output.
 155      * @param size    the number of log records to buffer (must be greater than zero)
 156      * @param pushLevel  message level to push on
 157      *
 158      * @throws IllegalArgumentException if {@code size is <= 0}
 159      */
 160     public MemoryHandler(Handler target, int size, Level pushLevel) {
 161         if (target == null || pushLevel == null) {
 162             throw new NullPointerException();
 163         }
 164         if (size <= 0) {
 165             throw new IllegalArgumentException();
 166         }
 167         sealed = false;
 168         configure();
 169         sealed = true;
 170         this.target = target;
 171         this.pushLevel = pushLevel;
 172         this.size = size;
 173         init();
 174     }
 175 
 176     /**
 177      * Store a <tt>LogRecord</tt> in an internal buffer.
 178      * <p>
 179      * If there is a <tt>Filter</tt>, its <tt>isLoggable</tt>
 180      * method is called to check if the given log record is loggable.
 181      * If not we return.  Otherwise the given record is copied into
 182      * an internal circular buffer.  Then the record's level property is
 183      * compared with the <tt>pushLevel</tt>. If the given level is
 184      * greater than or equal to the <tt>pushLevel</tt> then <tt>push</tt>
 185      * is called to write all buffered records to the target output
 186      * <tt>Handler</tt>.
 187      *
 188      * @param  record  description of the log event. A null record is
 189      *                 silently ignored and is not published




  99     // javadoc.
 100     private void configure() {
 101         LogManager manager = LogManager.getLogManager();
 102         String cname = getClass().getName();
 103 
 104         pushLevel = manager.getLevelProperty(cname +".push", Level.SEVERE);
 105         size = manager.getIntProperty(cname + ".size", DEFAULT_SIZE);
 106         if (size <= 0) {
 107             size = DEFAULT_SIZE;
 108         }
 109         setLevel(manager.getLevelProperty(cname +".level", Level.ALL));
 110         setFilter(manager.getFilterProperty(cname +".filter", null));
 111         setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));
 112     }
 113 
 114     /**
 115      * Create a <tt>MemoryHandler</tt> and configure it based on
 116      * <tt>LogManager</tt> configuration properties.
 117      */
 118     public MemoryHandler() {
 119         doWithControlPermission(this::configure);


 120 
 121         LogManager manager = LogManager.getLogManager();
 122         String handlerName = getClass().getName();
 123         String targetName = manager.getProperty(handlerName+".target");
 124         if (targetName == null) {
 125             throw new RuntimeException("The handler " + handlerName
 126                     + " does not specify a target");
 127         }
 128         Class<?> clz;
 129         try {
 130             clz = ClassLoader.getSystemClassLoader().loadClass(targetName);
 131             target = (Handler) clz.newInstance();
 132         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
 133             throw new RuntimeException("MemoryHandler can't load handler target \"" + targetName + "\"" , e);
 134         }
 135         init();
 136     }
 137 
 138     // Initialize.  Size is a count of LogRecords.
 139     private void init() {


 145     /**
 146      * Create a <tt>MemoryHandler</tt>.
 147      * <p>
 148      * The <tt>MemoryHandler</tt> is configured based on <tt>LogManager</tt>
 149      * properties (or their default values) except that the given <tt>pushLevel</tt>
 150      * argument and buffer size argument are used.
 151      *
 152      * @param target  the Handler to which to publish output.
 153      * @param size    the number of log records to buffer (must be greater than zero)
 154      * @param pushLevel  message level to push on
 155      *
 156      * @throws IllegalArgumentException if {@code size is <= 0}
 157      */
 158     public MemoryHandler(Handler target, int size, Level pushLevel) {
 159         if (target == null || pushLevel == null) {
 160             throw new NullPointerException();
 161         }
 162         if (size <= 0) {
 163             throw new IllegalArgumentException();
 164         }
 165         doWithControlPermission(this::configure);


 166         this.target = target;
 167         this.pushLevel = pushLevel;
 168         this.size = size;
 169         init();
 170     }
 171 
 172     /**
 173      * Store a <tt>LogRecord</tt> in an internal buffer.
 174      * <p>
 175      * If there is a <tt>Filter</tt>, its <tt>isLoggable</tt>
 176      * method is called to check if the given log record is loggable.
 177      * If not we return.  Otherwise the given record is copied into
 178      * an internal circular buffer.  Then the record's level property is
 179      * compared with the <tt>pushLevel</tt>. If the given level is
 180      * greater than or equal to the <tt>pushLevel</tt> then <tt>push</tt>
 181      * is called to write all buffered records to the target output
 182      * <tt>Handler</tt>.
 183      *
 184      * @param  record  description of the log event. A null record is
 185      *                 silently ignored and is not published