/** * Constructs a {@code Handler} object with a default error manager instance * {@code ErrorManager}, the default encoding, and the default logging * level {@code Level.ALL}. It has no filter and no formatter. */ protected Handler() { this.errorMan = new ErrorManager(); this.level = DEFAULT_LEVEL; this.encoding = null; this.filter = null; this.formatter = null; this.prefix = this.getClass().getName(); }
/** * Constructs a {@code StreamHandler} object with the supplied output stream * and formatter. * * @param os * the output stream this handler writes to. * @param formatter * the formatter this handler uses to format the output. * @throws NullPointerException * if {@code os} or {@code formatter} is {@code null}. */ public StreamHandler(java.io.OutputStream os, Formatter formatter) : this() { if (os == null) { // logging.2=The OutputStream parameter is null throw new java.lang.NullPointerException("The OutputStream parameter is null"); //$NON-NLS-1$ } if (formatter == null) { // logging.3=The Formatter parameter is null. throw new java.lang.NullPointerException("The Formatter parameter is null."); //$NON-NLS-1$ } this.os = os; internalSetFormatter(formatter); }
/** * init the common properties, including filter, level, formatter, and * encoding */ internal void initProperties(String defaultLevel, String defaultFilter, String defaultFormatter, String defaultEncoding) { LogManager manager = LogManager.getLogManager(); // set filter String filterName = manager.getProperty(prefix + ".filter"); //$NON-NLS-1$ if (null != filterName) { try { filter = (Filter) getCustomizeInstance(filterName); } catch (java.lang.Exception e1) { printInvalidPropMessage("filter", filterName, e1); //$NON-NLS-1$ filter = (Filter) getDefaultInstance(defaultFilter); } } else { filter = (Filter) getDefaultInstance(defaultFilter); } // set level String levelName = manager.getProperty(prefix + ".level"); //$NON-NLS-1$ if (null != levelName) { try { level = Level.parse(levelName); } catch (java.lang.Exception e) { printInvalidPropMessage("level", levelName, e); //$NON-NLS-1$ level = Level.parse(defaultLevel); } } else { level = Level.parse(defaultLevel); } // set formatter String formatterName = manager.getProperty(prefix + ".formatter"); //$NON-NLS-1$ if (null != formatterName) { try { formatter = (Formatter) getCustomizeInstance(formatterName); } catch (java.lang.Exception e) { printInvalidPropMessage("formatter", formatterName, e); //$NON-NLS-1$ formatter = (Formatter) getDefaultInstance(defaultFormatter); } } else { formatter = (Formatter) getDefaultInstance(defaultFormatter); } // set encoding String encodingName = manager.getProperty(prefix + ".encoding"); //$NON-NLS-1$ try { internalSetEncoding(encodingName); } catch (java.io.UnsupportedEncodingException e) { printInvalidPropMessage("encoding", encodingName, e); //$NON-NLS-1$ } }
/** * Sets the formatter to be used by this handler. This internal method does * not check security. * * @param newFormatter * the formatter to set. */ protected void internalSetFormatter(Formatter newFormatter) { if (null == newFormatter) { throw new java.lang.NullPointerException(); } this.formatter = newFormatter; }
/** * Sets the formatter to be used by this handler. * * @param newFormatter * the formatter to set. * @throws NullPointerException * if {@code newFormatter} is {@code null}. * @throws SecurityException * if a security manager determines that the caller does not * have the required permission. */ public void setFormatter(Formatter newFormatter) { LogManager.getLogManager().checkAccess(); internalSetFormatter(newFormatter); }