/**
  * @param logConfig to get configuration data from, and subscribe for future updates
  * @param loggerName
  * @param logThrottle optional log throttle, may be null if not used.
  */
 public StdOutConsoleHandler(LogConfig logConfig, String loggerName, LogThrottle logThrottle) {
   this.logConfig = logConfig;
   this.loggerName = loggerName;
   this.logThrottle = logThrottle;
   setOutputStream(System.out);
   configureLogging(logConfig);
   logConfig.addSubscriber(
       this); // passing "this" should only be done when this object is fully constructed.
 }
Example #2
0
 public static synchronized LocalOnlyAcsLogger getInstance(String namespace, Level level) {
   if (instance == null) {
     LogConfig testLogConfig = new LogConfig();
     testLogConfig.setDefaultMinLogLevelLocal(AcsLogLevel.getNativeLevel(level).getAcsLevel());
     instance = new LocalOnlyAcsLogger(namespace, testLogConfig);
     instance.setUseParentHandlers(false);
     Handler logHandler = new StdOutConsoleHandler(testLogConfig, namespace, null);
     logHandler.setFormatter(
         new AcsXMLLogFormatter() {
           public String format(LogRecord lr) {
             String xml = super.format(lr);
             return xml + '\n';
           }
         });
     logHandler.setLevel(level);
     instance.addHandler(logHandler);
   }
   return instance;
 }
  /**
   * @see
   *     alma.acs.logging.config.LogConfigSubscriber#configureLogging(alma.acs.logging.config.LogConfig)
   */
  public void configureLogging(LogConfig newLogConfig) {
    // just in case some day LogConfig is no longer used as a singleton
    this.logConfig = newLogConfig;

    try {
      AcsLogLevelDefinition minLogLevelACS =
          AcsLogLevelDefinition.fromXsdLogLevel(
              logConfig.getNamedLoggerConfig(loggerName).getMinLogLevelLocal());
      setLevel(AcsLogLevel.getLowestMatchingJdkLevel(minLogLevelACS));
    } catch (Exception ex) {
      publish(
          new LogRecord(Level.WARNING, "Failed to configure stdout log handler: " + ex.toString()));
    }
  }
 /**
  * Override <tt>StreamHandler.close</tt> to do a flush but not to close the output stream. That
  * is, we do <b>not</b> close <tt>System.err</tt>.
  */
 public void close() {
   flush();
   logConfig.removeSubscriber(this);
 }