📄 logger.java
字号:
/** * Retrieve the localization resource bundle name for this * logger. Note that if the result is null, then the Logger * will use a resource bundle name inherited from its parent. * * @return localization bundle name (may be null) */ public String getResourceBundleName() { return resourceBundleName; } /** * Set a filter to control output on this Logger. * <P> * After passing the initial "level" check, the Logger will * call this Filter to check if a log record should really * be published. * * @param newFilter a filter object (may be null) * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ public void setFilter(Filter newFilter) throws SecurityException { if (!anonymous) { manager.checkAccess(); } filter = newFilter; } /** * Get the current filter for this Logger. * * @return a filter object (may be null) */ public Filter getFilter() { return filter; } /** * Log a LogRecord. * <p> * All the other logging methods in this class call through * this method to actually perform any logging. Subclasses can * override this single method to capture all log activity. * * @param record the LogRecord to be published */ public void log(LogRecord record) { if (record.getLevel().intValue() < levelValue || levelValue == offValue) { return; } synchronized (this) { if (filter != null && !filter.isLoggable(record)) { return; } } // Post the LogRecord to all our Handlers, and then to // our parents' handlers, all the way up the tree. Logger logger = this; while (logger != null) { Handler targets[] = logger.getHandlers(); if (targets != null) { for (int i = 0; i < targets.length; i++) { targets[i].publish(record); } } if (!logger.getUseParentHandlers()) { break; } logger = logger.getParent(); } } // private support method for logging. // We fill in the logger name, resource bundle name, and // resource bundle and then call "void log(LogRecord)". private void doLog(LogRecord lr) { lr.setLoggerName(name); String ebname = getEffectiveResourceBundleName(); if (ebname != null) { lr.setResourceBundleName(ebname); lr.setResourceBundle(findResourceBundle(ebname)); } log(lr); } //================================================================ // Start of convenience methods WITHOUT className and methodName //================================================================ /** * Log a message, with no arguments. * <p> * If the logger is currently enabled for the given message * level then the given message is forwarded to all the * registered output Handler objects. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param msg The string message (or a key in the message catalog) */ public void log(Level level, String msg) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); doLog(lr); } /** * Log a message, with one object parameter. * <p> * If the logger is currently enabled for the given message * level then a corresponding LogRecord is created and forwarded * to all the registered output Handler objects. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param msg The string message (or a key in the message catalog) * @param param1 parameter to the message */ public void log(Level level, String msg, Object param1) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); Object params[] = { param1 }; lr.setParameters(params); doLog(lr); } /** * Log a message, with an array of object arguments. * <p> * If the logger is currently enabled for the given message * level then a corresponding LogRecord is created and forwarded * to all the registered output Handler objects. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param msg The string message (or a key in the message catalog) * @param params array of parameters to the message */ public void log(Level level, String msg, Object params[]) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setParameters(params); doLog(lr); } /** * Log a message, with associated Throwable information. * <p> * If the logger is currently enabled for the given message * level then the given arguments are stored in a LogRecord * which is forwarded to all registered output handlers. * <p> * Note that the thrown argument is stored in the LogRecord thrown * property, rather than the LogRecord parameters property. Thus is it * processed specially by output Formatters and is not treated * as a formatting parameter to the LogRecord message property. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param msg The string message (or a key in the message catalog) * @param thrown Throwable associated with log message. */ public void log(Level level, String msg, Throwable thrown) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setThrown(thrown); doLog(lr); } //================================================================ // Start of convenience methods WITH className and methodName //================================================================ /** * Log a message, specifying source class and method, * with no arguments. * <p> * If the logger is currently enabled for the given message * level then the given message is forwarded to all the * registered output Handler objects. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param sourceClass name of class that issued the logging request * @param sourceMethod name of method that issued the logging request * @param msg The string message (or a key in the message catalog) */ public void logp(Level level, String sourceClass, String sourceMethod, String msg) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setSourceClassName(sourceClass); lr.setSourceMethodName(sourceMethod); doLog(lr); } /** * Log a message, specifying source class and method, * with a single object parameter to the log message. * <p> * If the logger is currently enabled for the given message * level then a corresponding LogRecord is created and forwarded * to all the registered output Handler objects. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param sourceClass name of class that issued the logging request * @param sourceMethod name of method that issued the logging request * @param msg The string message (or a key in the message catalog) * @param param1 Parameter to the log message. */ public void logp(Level level, String sourceClass, String sourceMethod, String msg, Object param1) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setSourceClassName(sourceClass); lr.setSourceMethodName(sourceMethod); Object params[] = { param1 }; lr.setParameters(params); doLog(lr); } /** * Log a message, specifying source class and method, * with an array of object arguments. * <p> * If the logger is currently enabled for the given message * level then a corresponding LogRecord is created and forwarded * to all the registered output Handler objects. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param sourceClass name of class that issued the logging request * @param sourceMethod name of method that issued the logging request * @param msg The string message (or a key in the message catalog) * @param params Array of parameters to the message */ public void logp(Level level, String sourceClass, String sourceMethod, String msg, Object params[]) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setSourceClassName(sourceClass); lr.setSourceMethodName(sourceMethod); lr.setParameters(params); doLog(lr); } /** * Log a message, specifying source class and method, * with associated Throwable information. * <p> * If the logger is currently enabled for the given message * level then the given arguments are stored in a LogRecord * which is forwarded to all registered output handlers. * <p> * Note that the thrown argument is stored in the LogRecord thrown * property, rather than the LogRecord parameters property. Thus is it * processed specially by output Formatters and is not treated * as a formatting parameter to the LogRecord message property. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param sourceClass name of class that issued the logging request * @param sourceMethod name of method that issued the logging request * @param msg The string message (or a key in the message catalog) * @param thrown Throwable associated with log message. */ public void logp(Level level, String sourceClass, String sourceMethod, String msg, Throwable thrown) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setSourceClassName(sourceClass); lr.setSourceMethodName(sourceMethod); lr.setThrown(thrown); doLog(lr); } //========================================================================= // Start of convenience methods WITH className, methodName and bundle name. //========================================================================= // Private support method for logging for "logrb" methods. // We fill in the logger name, resource bundle name, and // resource bundle and then call "void log(LogRecord)". private void doLog(LogRecord lr, String rbname) { lr.setLoggerName(name); if (rbname != null) { lr.setResourceBundleName(rbname); lr.setResourceBundle(findResourceBundle(rbname)); } log(lr); } /** * Log a message, specifying source class, method, and resource bundle name * with no arguments. * <p> * If the logger is currently enabled for the given message * level then the given message is forwarded to all the * registered output Handler objects. * <p> * The msg string is localized using the named resource bundle. If the * resource bundle name is null, then the msg string is not localized. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param sourceClass name of class that issued the logging request * @param sourceMethod name of method that issued the logging request * @param bundleName name of resource bundle to localize msg * @param msg The string message (or a key in the message catalog) * @throws MissingResourceException if no suitable ResourceBundle can * be found. */ public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msg) { if (level.intValue() < levelValue || levelValue == offValue) { return; } LogRecord lr = new LogRecord(level, msg); lr.setSourceClassName(sourceClass); lr.setSourceMethodName(sourceMethod); doLog(lr, bundleName); } /** * Log a message, specifying source class, method, and resource bundle name, * with a single object parameter to the log message. * <p> * If the logger is currently enabled for the given message * level then a corresponding LogRecord is created and forwarded * to all the registered output Handler objects. * <p> * The msg string is localized using the named resource bundle. If the * resource bundle name is null, then the msg string is not localized. * <p> * @param level One of the message level identifiers, e.g. SEVERE * @param sourceClass name of class that issued the logging request * @param sourceMethod name of method that issued the logging request * @param bundleName name of resource bundle to localize msg * @param msg The string message (or a key in the message catalog)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -