/** * 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(); }
/** * Sets the level on {@code logger} to {@code newLevel}. Any child loggers * currently inheriting their level from {@code logger} will be updated * recursively. * * @param newLevel the new minimum logging threshold. If null, the logger's * parent level will be used; or {@code Level.INFO} for loggers with no * parent. */ internal void setLevelRecursively(Logger logger, Level newLevel) { lock (this) { int previous = logger.levelIntVal; logger.levelObjVal = newLevel; if (newLevel == null) { logger.levelIntVal = logger.parent != null ? logger.parent.levelIntVal : Level.INFO.intValue(); } else { logger.levelIntVal = newLevel.intValue(); } if (previous != logger.levelIntVal) { foreach (Logger child in logger.children) { if (child.levelObjVal == null) { setLevelRecursively(child, null); } } } } }
/** * Sets the logging level. * * @param level * the level to set. * @throws NullPointerException * if {@code level} is {@code null}. */ public void setLevel(Level level) { if (null == level) { // logging.4=The 'level' parameter is null. throw new java.lang.NullPointerException("The 'level' parameter is null."); //$NON-NLS-1$ } this.level = level; }
/** * Constructs a {@code LogRecord} object using the supplied the logging * level and message. The millis property is set to the current time. The * sequence property is set to a new unique value, allocated in increasing * order within the virtual machine. The thread ID is set to a unique value * for the current thread. All other properties are set to {@code null}. * * @param level * the logging level, may not be {@code null}. * @param msg * the raw message. * @throws NullPointerException * if {@code level} is {@code null}. */ public LogRecord(Level level, String msg) { if (null == level) { // logging.4=The 'level' parameter is null. throw new java.lang.NullPointerException("The 'level' parameter is null."); //$NON-NLS-1$ } this.level = level; this.message = msg; this.millis = java.lang.SystemJ.currentTimeMillis(); lock (typeof(LogRecord).getClass()) { this.sequenceNumber = currentSequenceNumber++; java.lang.Integer id = currentThreadId.get(); if (null == id) { this.threadID = initThreadId; currentThreadId.set(java.lang.Integer.valueOf(initThreadId++)); } else { this.threadID = id.intValue(); } } this.sourceClassName = null; this.sourceMethodName = null; this.loggerName = null; this.parameters = null; this.resourceBundle = null; this.resourceBundleName = null; this.thrown = null; }
/** * Default constructor, construct and init a {@code MemoryHandler} using * {@code LogManager} properties or default values. * * @throws RuntimeException * if property value are invalid and no default value could be * used. */ public MemoryHandler() : base() { String className = this.getClass().getName(); // init target String targetName = manager.getProperty(className + ".target"); //$NON-NLS-1$ try { target = (Handler) java.lang.Class.forName(targetName).newInstance(); } catch (Exception e) { // logging.10=Cannot load target handler:{0} throw new java.lang.RuntimeException("Cannot load target handler: "+ //$NON-NLS-1$ targetName); } // init size String sizeString = manager.getProperty(className + ".size"); //$NON-NLS-1$ if (null != sizeString) { try { size = java.lang.Integer.parseInt(sizeString); if (size <= 0) { size = DEFAULT_SIZE; } } catch (java.lang.Exception e) { printInvalidPropMessage(className + ".size", sizeString, e); //$NON-NLS-1$ } } // init push level String pushName = manager.getProperty(className + ".push"); //$NON-NLS-1$ if (null != pushName) { try { pushJ = Level.parse(pushName); } catch (java.lang.Exception e) { printInvalidPropMessage(className + ".push", pushName, e); //$NON-NLS-1$ } } // init other properties which are common for all Handler initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$ buffer = new LogRecord[size]; }
/** * Set the push level. The push level is used to check the push action * triggering. When a new {@code LogRecord} is put into the internal * buffer and its level is not less than the push level, the push action * will be triggered. Note that set new push level won't trigger push action. * * @param newLevel * the new level to set. * @throws SecurityException * if security manager exists and it determines that caller * does not have the required permissions to control this handler. */ public void setPushLevel(Level newLevel) { manager.checkAccess(); newLevel.intValue(); this.pushJ = newLevel; }
/** * Construct and init a {@code MemoryHandler} using given target, size and * push level, other properties using {@code LogManager} properties or * default values. * * @param target * the given {@code Handler} to output * @param size * the maximum number of buffered {@code LogRecord}, greater than * zero * @param pushLevel * the push level * @throws IllegalArgumentException * if {@code size <= 0} * @throws RuntimeException * if property value are invalid and no default value could be * used. */ public MemoryHandler(Handler target, int size, Level pushLevel) { if (size <= 0) { // logging.11=Size must be positive. throw new java.lang.IllegalArgumentException("Size must be positive."); //$NON-NLS-1$ } target.getLevel(); pushLevel.intValue(); this.target = target; this.size = size; this.pushJ = pushLevel; initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$ buffer = new LogRecord[size]; }
/** * This method is for compatibility. Tests written to the reference * implementation API imply that the isLoggable() method is not called * directly. This behavior is important because subclass may override * isLoggable() method, so that affect the result of log methods. */ private bool internalIsLoggable(Level l) { int effectiveLevel = levelIntVal; if (effectiveLevel == Level.OFF.intValue()) { // always return false if the effective level is off return false; } return l.intValue() >= effectiveLevel; }
internal void reset() { levelObjVal = null; levelIntVal = Level.INFO.intValue(); foreach (Handler handler in handlers) { try { if (handlers.remove(handler)) { handler.close(); } } catch (Exception ignored) { } } }
/** * Sets the logging level for this logger. A {@code null} level indicates * that this logger will inherit its parent's level. * * @param newLevel * the logging level to set. * @throws SecurityException * if a security manager determines that the caller does not * have the required permission. */ public void setLevel(Level newLevel) { // Anonymous loggers can always set the level LogManager logManager = LogManager.getLogManager(); if (this.isNamed) { logManager.checkAccess(); } logManager.setLevelRecursively(this, newLevel); }
/** * Logs a message of the specified level. The message is transmitted to all * subscribed handlers. * * @param logLevel * the level of the specified message. * @param msg * the message to log. */ public void log(Level logLevel, String msg) { if (!internalIsLoggable(logLevel)) { return; } LogRecord record = new LogRecord(logLevel, msg); record.setLoggerName(this.name); setResourceBundle(record); log(record); }
/** * Determines whether this logger will actually log messages of the * specified level. The effective level used to do the determination may be * inherited from its parent. The default level is {@code Level.INFO}. * * @param l * the level to check. * @return {@code true} if this logger will actually log this level, * otherwise {@code false}. */ public bool isLoggable(Level l) { return internalIsLoggable(l); }
/** * 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 logging level of the messages logged by this handler, levels * lower than this value will be dropped. * * @param newLevel * the logging level to set. * @throws NullPointerException * if {@code newLevel} is {@code null}. * @throws SecurityException * if a security manager determines that the caller does not * have the required permission. */ public void setLevel(Level newLevel) { if (null == newLevel) { throw new java.lang.NullPointerException(); } LogManager.getLogManager().checkAccess(); this.level = newLevel; }