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

Print this page




 141 
 142     /**
 143      * Close the <tt>Handler</tt> and free all associated resources.
 144      * <p>
 145      * The close method will perform a <tt>flush</tt> and then close the
 146      * <tt>Handler</tt>.   After close has been called this <tt>Handler</tt>
 147      * should no longer be used.  Method calls may either be silently
 148      * ignored or may throw runtime exceptions.
 149      *
 150      * @exception  SecurityException  if a security manager exists and if
 151      *             the caller does not have <tt>LoggingPermission("control")</tt>.
 152      */
 153     public abstract void close() throws SecurityException;
 154 
 155     /**
 156      * Set a <tt>Formatter</tt>.  This <tt>Formatter</tt> will be used
 157      * to format <tt>LogRecords</tt> for this <tt>Handler</tt>.
 158      * <p>
 159      * Some <tt>Handlers</tt> may not use <tt>Formatters</tt>, in
 160      * which case the <tt>Formatter</tt> will be remembered, but not used.
 161      * <p>
 162      * @param newFormatter the <tt>Formatter</tt> to use (may not be null)
 163      * @exception  SecurityException  if a security manager exists and if
 164      *             the caller does not have <tt>LoggingPermission("control")</tt>.
 165      */
 166     public synchronized void setFormatter(Formatter newFormatter) throws SecurityException {
 167         checkPermission();
 168         // Check for a null pointer:
 169         newFormatter.getClass();
 170         formatter = newFormatter;
 171     }
 172 
 173     /**
 174      * Return the <tt>Formatter</tt> for this <tt>Handler</tt>.
 175      * @return the <tt>Formatter</tt> (may be null).
 176      */
 177     public Formatter getFormatter() {
 178         return formatter;
 179     }
 180 
 181     /**


 312     }
 313 
 314     /**
 315      * Get the log level specifying which messages will be
 316      * logged by this <tt>Handler</tt>.  Message levels lower
 317      * than this level will be discarded.
 318      * @return  the level of messages being logged.
 319      */
 320     public Level getLevel() {
 321         return logLevel;
 322     }
 323 
 324     /**
 325      * Check if this <tt>Handler</tt> would actually log a given <tt>LogRecord</tt>.
 326      * <p>
 327      * This method checks if the <tt>LogRecord</tt> has an appropriate
 328      * <tt>Level</tt> and  whether it satisfies any <tt>Filter</tt>.  It also
 329      * may make other <tt>Handler</tt> specific checks that might prevent a
 330      * handler from logging the <tt>LogRecord</tt>. It will return false if
 331      * the <tt>LogRecord</tt> is null.
 332      * <p>
 333      * @param record  a <tt>LogRecord</tt>
 334      * @return true if the <tt>LogRecord</tt> would be logged.
 335      *
 336      */
 337     public boolean isLoggable(LogRecord record) {
 338         final int levelValue = getLevel().intValue();
 339         if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
 340             return false;
 341         }
 342         final Filter filter = getFilter();
 343         if (filter == null) {
 344             return true;
 345         }
 346         return filter.isLoggable(record);
 347     }
 348 
 349     // Package-private support method for security checks.
 350     // We check that the caller has appropriate security privileges
 351     // to update Handler state and if not throw a SecurityException.
 352     void checkPermission() throws SecurityException {


 141 
 142     /**
 143      * Close the <tt>Handler</tt> and free all associated resources.
 144      * <p>
 145      * The close method will perform a <tt>flush</tt> and then close the
 146      * <tt>Handler</tt>.   After close has been called this <tt>Handler</tt>
 147      * should no longer be used.  Method calls may either be silently
 148      * ignored or may throw runtime exceptions.
 149      *
 150      * @exception  SecurityException  if a security manager exists and if
 151      *             the caller does not have <tt>LoggingPermission("control")</tt>.
 152      */
 153     public abstract void close() throws SecurityException;
 154 
 155     /**
 156      * Set a <tt>Formatter</tt>.  This <tt>Formatter</tt> will be used
 157      * to format <tt>LogRecords</tt> for this <tt>Handler</tt>.
 158      * <p>
 159      * Some <tt>Handlers</tt> may not use <tt>Formatters</tt>, in
 160      * which case the <tt>Formatter</tt> will be remembered, but not used.
 161      *
 162      * @param newFormatter the <tt>Formatter</tt> to use (may not be null)
 163      * @exception  SecurityException  if a security manager exists and if
 164      *             the caller does not have <tt>LoggingPermission("control")</tt>.
 165      */
 166     public synchronized void setFormatter(Formatter newFormatter) throws SecurityException {
 167         checkPermission();
 168         // Check for a null pointer:
 169         newFormatter.getClass();
 170         formatter = newFormatter;
 171     }
 172 
 173     /**
 174      * Return the <tt>Formatter</tt> for this <tt>Handler</tt>.
 175      * @return the <tt>Formatter</tt> (may be null).
 176      */
 177     public Formatter getFormatter() {
 178         return formatter;
 179     }
 180 
 181     /**


 312     }
 313 
 314     /**
 315      * Get the log level specifying which messages will be
 316      * logged by this <tt>Handler</tt>.  Message levels lower
 317      * than this level will be discarded.
 318      * @return  the level of messages being logged.
 319      */
 320     public Level getLevel() {
 321         return logLevel;
 322     }
 323 
 324     /**
 325      * Check if this <tt>Handler</tt> would actually log a given <tt>LogRecord</tt>.
 326      * <p>
 327      * This method checks if the <tt>LogRecord</tt> has an appropriate
 328      * <tt>Level</tt> and  whether it satisfies any <tt>Filter</tt>.  It also
 329      * may make other <tt>Handler</tt> specific checks that might prevent a
 330      * handler from logging the <tt>LogRecord</tt>. It will return false if
 331      * the <tt>LogRecord</tt> is null.
 332      *
 333      * @param record  a <tt>LogRecord</tt>
 334      * @return true if the <tt>LogRecord</tt> would be logged.
 335      *
 336      */
 337     public boolean isLoggable(LogRecord record) {
 338         final int levelValue = getLevel().intValue();
 339         if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
 340             return false;
 341         }
 342         final Filter filter = getFilter();
 343         if (filter == null) {
 344             return true;
 345         }
 346         return filter.isLoggable(record);
 347     }
 348 
 349     // Package-private support method for security checks.
 350     // We check that the caller has appropriate security privileges
 351     // to update Handler state and if not throw a SecurityException.
 352     void checkPermission() throws SecurityException {