⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logger.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    if (isLoggable(Level.FINER))      logp(Level.FINER, sourceClass, sourceMethod, "RETURN");  }     public synchronized void exiting(String sourceClass,				   String sourceMethod,				   Object result)  {    if (isLoggable(Level.FINER))      logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result);  }   public synchronized void throwing(String sourceClass,				    String sourceMethod,				    Throwable thrown)  {    if (isLoggable(Level.FINER))      logp(Level.FINER, sourceClass, sourceMethod, "THROW", thrown);  }  /**   * Logs a message with severity level SEVERE, indicating a serious   * failure that prevents normal program execution.  Messages at this   * level should be understandable to an inexperienced, non-technical   * end user.  Ideally, they explain in simple words what actions the   * user can take in order to resolve the problem.   *   * @see Level#SEVERE   *   * @param message the message text, also used as look-up key if the   *                logger is localizing messages with a resource   *                bundle.  While it is possible to pass   *                <code>null</code>, this is not recommended, since   *                a logging message without text is unlikely to be   *                helpful.   */  public synchronized void severe(String message)  {    if (isLoggable(Level.SEVERE))      log(Level.SEVERE, message);  }  /**   * Logs a message with severity level WARNING, indicating a   * potential problem that does not prevent normal program execution.   * Messages at this level should be understandable to an   * inexperienced, non-technical end user.  Ideally, they explain in   * simple words what actions the user can take in order to resolve   * the problem.   *   * @see Level#WARNING   *   * @param message the message text, also used as look-up key if the   *                logger is localizing messages with a resource   *                bundle.  While it is possible to pass   *                <code>null</code>, this is not recommended, since   *                a logging message without text is unlikely to be   *                helpful.   */  public synchronized void warning(String message)  {    if (isLoggable(Level.WARNING))      log(Level.WARNING, message);  }  /**   * Logs a message with severity level INFO.  {@link Level#INFO} is   * intended for purely informational messages that do not indicate   * error or warning situations. In the default logging   * configuration, INFO messages will be written to the system   * console.  For this reason, the INFO level should be used only for   * messages that are important to end users and system   * administrators.  Messages at this level should be understandable   * to an inexperienced, non-technical user.   *   * @param message the message text, also used as look-up key if the   *                logger is localizing messages with a resource   *                bundle.  While it is possible to pass   *                <code>null</code>, this is not recommended, since   *                a logging message without text is unlikely to be   *                helpful.   */  public synchronized void info(String message)  {    if (isLoggable(Level.INFO))      log(Level.INFO, message);  }  /**   * Logs a message with severity level CONFIG.  {@link Level#CONFIG} is   * intended for static configuration messages, for example about the   * windowing environment, the operating system version, etc.   *   * @param message the message text, also used as look-up key if the   *     logger is localizing messages with a resource bundle.  While   *     it is possible to pass <code>null</code>, this is not   *     recommended, since a logging message without text is unlikely   *     to be helpful.   */  public synchronized void config(String message)  {    if (isLoggable(Level.CONFIG))      log(Level.CONFIG, message);  }  /**   * Logs a message with severity level FINE.  {@link Level#FINE} is   * intended for messages that are relevant for developers using   * the component generating log messages. Examples include minor,   * recoverable failures, or possible inefficiencies.   *   * @param message the message text, also used as look-up key if the   *                logger is localizing messages with a resource   *                bundle.  While it is possible to pass   *                <code>null</code>, this is not recommended, since   *                a logging message without text is unlikely to be   *                helpful.   */  public synchronized void fine(String message)  {    if (isLoggable(Level.FINE))      log(Level.FINE, message);  }  /**   * Logs a message with severity level FINER.  {@link Level#FINER} is   * intended for rather detailed tracing, for example entering a   * method, returning from a method, or throwing an exception.   *   * @param message the message text, also used as look-up key if the   *                logger is localizing messages with a resource   *                bundle.  While it is possible to pass   *                <code>null</code>, this is not recommended, since   *                a logging message without text is unlikely to be   *                helpful.   */  public synchronized void finer(String message)  {    if (isLoggable(Level.FINER))      log(Level.FINER, message);  }  /**   * Logs a message with severity level FINEST.  {@link Level#FINEST}   * is intended for highly detailed tracing, for example reaching a   * certain point inside the body of a method.   *   * @param message the message text, also used as look-up key if the   *                logger is localizing messages with a resource   *                bundle.  While it is possible to pass   *                <code>null</code>, this is not recommended, since   *                a logging message without text is unlikely to be   *                helpful.   */  public synchronized void finest(String message)  {    if (isLoggable(Level.FINEST))      log(Level.FINEST, message);  }  /**   * Adds a handler to the set of handlers that get notified   * when a log record is to be published.   *   * @param handler the handler to be added.   *   * @throws NullPointerException if <code>handler</code>   *     is <code>null</code>.   *   * @throws SecurityException if this logger is not anonymous, a   *     security manager exists, and the caller is not granted   *     the permission to control the logging infrastructure by   *     having LoggingPermission("control").  Untrusted code can   *     obtain an anonymous logger through the static factory method   *     {@link #getAnonymousLogger(java.lang.String) getAnonymousLogger}.   */  public synchronized void addHandler(Handler handler)    throws SecurityException  {    /* Throw a new NullPointerException if handler is null. */    handler.getClass();    /* An application is allowed to control an anonymous logger     * without having the permission to control the logging     * infrastructure.     */    if (!anonymous)      LogManager.getLogManager().checkAccess();    if (!handlerList.contains(handler))    {      handlerList.add(handler);      handlers = getHandlers();    }  }  /**   * Removes a handler from the set of handlers that get notified   * when a log record is to be published.   *   * @param handler the handler to be removed.   *   * @throws SecurityException if this logger is not anonymous, a   *     security manager exists, and the caller is not granted the   *     permission to control the logging infrastructure by having   *     LoggingPermission("control").  Untrusted code can obtain an   *     anonymous logger through the static factory method {@link   *     #getAnonymousLogger(java.lang.String) getAnonymousLogger}.   *   * @throws NullPointerException if <code>handler</code>   *     is <code>null</code>.   */  public synchronized void removeHandler(Handler handler)    throws SecurityException  {    /* An application is allowed to control an anonymous logger     * without having the permission to control the logging     * infrastructure.     */    if (!anonymous)      LogManager.getLogManager().checkAccess();    /* Throw a new NullPointerException if handler is null. */    handler.getClass();    handlerList.remove(handler);    handlers = getHandlers();  }  /**   * Returns the handlers currently registered for this Logger.   * When a log record has been deemed as being loggable,   * it will be passed to all registered handlers for   * publication.  In addition, if the logger uses parent handlers   * (see {@link #getUseParentHandlers() getUseParentHandlers}   * and {@link #setUseParentHandlers(boolean) setUseParentHandlers},   * the log record will be passed to the parent's handlers.   */  public synchronized Handler[] getHandlers()  {    /* We cannot return our internal handlers array     * because we do not have any guarantee that the     * caller would not change the array entries.     */    return (Handler[]) handlerList.toArray(new Handler[handlerList.size()]);  }  /**   * Returns whether or not this Logger forwards log records to   * handlers registered for its parent loggers.   *   * @return <code>false</code> if this Logger sends log records   *         merely to Handlers registered with itself;   *         <code>true</code> if this Logger sends log records   *         not only to Handlers registered with itself, but also   *         to those Handlers registered with parent loggers.   */  public synchronized boolean getUseParentHandlers()  {    return useParentHandlers;  }  /**   * Sets whether or not this Logger forwards log records to   * handlers registered for its parent loggers.   *   * @param useParentHandlers <code>false</code> to let this   *         Logger send log records merely to Handlers registered   *         with itself; <code>true</code> to let this Logger   *         send log records not only to Handlers registered   *         with itself, but also to those Handlers registered with   *         parent loggers.   *   * @throws SecurityException if this logger is not anonymous, a   *     security manager exists, and the caller is not granted   *     the permission to control the logging infrastructure by   *     having LoggingPermission("control").  Untrusted code can   *     obtain an anonymous logger through the static factory method   *     {@link #getAnonymousLogger(java.lang.String) getAnonymousLogger}.   *   */  public synchronized void setUseParentHandlers(boolean useParentHandlers)  {    /* An application is allowed to control an anonymous logger     * without having the permission to control the logging     * infrastructure.     */    if (!anonymous)      LogManager.getLogManager().checkAccess();    this.useParentHandlers = useParentHandlers;  }  /**   * Returns the parent of this logger.  By default, the parent is   * assigned by the LogManager by inspecting the logger's name.   *   * @return the parent of this logger (as detemined by the LogManager   *     by inspecting logger names), the root logger if no other   *     logger has a name which is a prefix of this logger's name, or   *     <code>null</code> for the root logger.   */  public synchronized Logger getParent()  {    return parent;  }  /**   * Sets the parent of this logger.  Usually, applications do not   * call this method directly.  Instead, the LogManager will ensure   * that the tree of loggers reflects the hierarchical logger   * namespace.  Basically, this method should not be public at all,   * but the GNU implementation follows the API specification.   *   * @throws NullPointerException if <code>parent</code> is   *     <code>null</code>.   *   * @throws SecurityException if this logger is not anonymous, a   *     security manager exists, and the caller is not granted   *     the permission to control the logging infrastructure by   *     having LoggingPermission("control").  Untrusted code can   *     obtain an anonymous logger through the static factory method   *     {@link #getAnonymousLogger(java.lang.String) getAnonymousLogger}.   */  public synchronized void setParent(Logger parent)  {    LogManager lm;    /* Throw a new NullPointerException if parent is null. */    parent.getClass();    lm = LogManager.getLogManager();    if (this == lm.rootLogger)        throw new IllegalArgumentException(          "only the root logger can have a null parent");    /* An application is allowed to control an anonymous logger     * without having the permission to control the logging     * infrastructure.     */    if (!anonymous)      LogManager.getLogManager().checkAccess();    this.parent = parent;  }    /**   * Gets the StackTraceElement of the first class that is not this class.   * That should be the initial caller of a logging method.   * @return caller of the initial logging method or null if unknown.   */  private StackTraceElement getCallerStackFrame()  {    Throwable t = new Throwable();    StackTraceElement[] stackTrace = t.getStackTrace();    int index = 0;    // skip to stackentries until this class    while(index < stackTrace.length	  && !stackTrace[index].getClassName().equals(getClass().getName()))      index++;    // skip the stackentries of this class    while(index < stackTrace.length	  && stackTrace[index].getClassName().equals(getClass().getName()))      index++;    return index < stackTrace.length ? stackTrace[index] : null;  }    /**   * Reset and close handlers attached to this logger. This function is package   * private because it must only be avaiable to the LogManager.   */  void resetLogger()  {    for (int i = 0; i < handlers.length; i++)      {        handlers[i].close();        handlerList.remove(handlers[i]);      }    handlers = getHandlers();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -