Package backend.controller

Source Code of backend.controller.BackendLogger

package backend.controller;

import java.io.OutputStream;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;

public class BackendLogger {

  private static Logger logger = Logger.getLogger("Backend");

  private static BackendLogger instance_ = new BackendLogger();

  private BackendLogger(OutputStream... streams) {
    for (OutputStream stream : streams) {
      logger.addHandler(new StreamHandler(stream, new SimpleFormatter()));
    }
    logger.setLevel(Level.ALL);
  }

  public static BackendLogger getInstance() {
    return instance_;
  }

  public synchronized void flush() {
    for (Handler h : logger.getHandlers()) {
      if (h instanceof StreamHandler) {
        ((StreamHandler) h).flush();
      }
    }
  }

  public void entering(String sourceClass, String sourceMethod,
      Object... params) {
    logger.entering(sourceClass, sourceMethod, params);
    flush();
  }

  public void entering(String sourceClass, String sourceMethod) {
    logger.entering(sourceClass, sourceMethod);
    flush();
  }

  public void exiting(String sourceClass, String sourceMethod, Object result) {
    logger.exiting(sourceClass, sourceMethod, result);
    flush();
  }

  public void exiting(String sourceClass, String sourceMethod) {
    logger.exiting(sourceClass, sourceMethod);
    flush();
  }

  public void fine(String msg) {
    logger.fine(msg);
    flush();
  }

  public void finer(String msg) {
    logger.finer(msg);
    flush();
  }

  public void finest(String msg) {
    logger.finest(msg);
    flush();
  }

  public void info(String msg) {
    logger.info(msg);
    flush();
  }

  public void severe(String msg) {
    logger.severe(msg);
    flush();
  }

  public void throwing(String sourceClass, String sourceMethod,
      Throwable thrown) {
    logger.throwing(sourceClass, sourceMethod, thrown);
    flush();
  }

  public void warning(String msg) {
    logger.warning(msg);
    flush();
  }

  public void setLevel(Level newLevel) throws SecurityException {
    logger.setLevel(newLevel);
    flush();
  }
}
TOP

Related Classes of backend.controller.BackendLogger

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.