Java Tutorial/Log/LogManager

Материал из Java эксперт
Перейти к: навигация, поиск

Determining When the Logging Configuration Properties are Reread

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.logging.LogManager;
public class Main {
  public static void main(String[] argv) throws Exception {
    // Register for the event
    LogManager.getLogManager().addPropertyChangeListener(new PropertyChangeListener() {
      // This method is called when configuration file is reread
      public void propertyChange(PropertyChangeEvent evt) {
        String propName = evt.getPropertyName();
        Object oldValue = evt.getOldValue();
        Object newValue = evt.getOldValue();
        // All values are null
      }
    });
  }
}





Remote ConfigReader with URLConnection

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.LogManager;
public class Main {
  public static void main(String[] argv) throws Exception {
    URLConnection urlConn = null;
    InputStream inStream = null;
    LogManager manager = null;
    URL url = new URL("http://www.xyz.ru/config.properties");
    urlConn = url.openConnection();
    inStream = urlConn.getInputStream();
    manager = LogManager.getLogManager();
    manager.readConfiguration(inStream);
  }
}