public void shutdown() {
    LOG.info("Uninstalling SLF4J Bridge");

    if (SLF4JBridgeHandler.isInstalled()) {
      SLF4JBridgeHandler.uninstall();
    }
  }
  public void initialise() {
    LOG.info("Installing SLF4J Bridge");

    removeDefaultJULLoggingHandlers();

    if (!SLF4JBridgeHandler.isInstalled()) {
      SLF4JBridgeHandler.install();
    }
  }
예제 #3
0
  public MyApplication() {
    super();
    // Optionally remove existing handlers attached to j.u.l root logger
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    // add SLF4JBridgeHandler to j.u.l's root logger, should be done once during
    // the initialization phase of your application
    SLF4JBridgeHandler.install();

    packages("provider", "rest");

    register(new LoggingFilter(log, true));
  }
  @Override
  public void start() throws Exception {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();

    Database database = new Database(new AppConfiguration("events.properties"));
    Flyway flyway = new Flyway();
    flyway.setDataSource(database.getDataSource());
    flyway.migrate();

    addHandler(shutdownHandler());
    addHandler(createWebAppContext("/events"));
    addHandler(createRedirectContextHandler("/", "/events"));
    super.start();
  }
  @Override
  public void destroy() {
    super.destroy();

    // Activity log
    UserActivity.log(Config.SYSTEM_USER, "MISC_OPENKM_STOP", null, null, null);

    // Invoke stop
    stop(this);

    try {
      // Database shutdown
      log.info("*** Hibernate shutdown ***");
      HibernateUtil.closeSessionFactory();
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }

    try {
      // Call only once during destroy time of your application
      // @see http://issues.openkm.com/view.php?id=1577
      SLF4JBridgeHandler.uninstall();
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
  }
  protected AbstractNexusIntegrationTest(String testRepositoryId) {
    // we also need to setup a couple fields, that need to be pulled out of a bundle
    this.testRepositoryId = testRepositoryId;
    // this.nexusTestRepoUrl = baseNexusUrl + REPOSITORY_RELATIVE_URL + testRepositoryId + "/";

    InputStream is = null;

    Properties props = new Properties();
    try {
      is = getClass().getResourceAsStream("/log4j.properties");

      if (is != null) {
        props.load(is);
        PropertyConfigurator.configure(props);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.close(is);
    }

    // configure the logging
    SLF4JBridgeHandler.install();

    // redirect filePrefs
    FilePreferencesFactory.setPreferencesFile(
        ITAppBooterCustomizer.getFilePrefsFile(new File(getNexusBaseDir()), getTestId()));
  }
예제 #7
0
 /* (non-Javadoc)
  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
  */
 @Override
 public void start(BundleContext bundleContext) throws Exception {
   mLogger.debug("earlyStartup slf4j SLF4JBridgeHandler...");
   java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
   Handler[] handlers = rootLogger.getHandlers();
   for (Handler handler : handlers) {
     rootLogger.removeHandler(handler);
   }
   org.slf4j.bridge.SLF4JBridgeHandler.install();
 }
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    // Jersey uses java.util.logging - bridge to slf4
    java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (int i = 0; i < handlers.length; i++) {
      rootLogger.removeHandler(handlers[i]);
    }
    SLF4JBridgeHandler.install();

    LOGGER.info("jul-to-slf4j installed");
  }
  @Override
  public void init() throws ServletException {
    super.init();
    ServletContext sc = getServletContext();

    // Read configuration file
    Properties config = Config.load(sc);

    // Call only once during initialization time of your application
    // @see http://issues.openkm.com/view.php?id=1577
    SLF4JBridgeHandler.install();

    // Get OpenKM version
    WarUtils.readAppVersion(sc);
    log.info("*** Application version: {} ***", WarUtils.getAppVersion());

    // Database initialize
    log.info("*** Hibernate initialize ***");
    HibernateUtil.getSessionFactory();

    // Create missing directories
    // NOTE: Should be executed AFTER Hibernate initialization because if in created mode
    // initialization will drop these directories
    createMissingDirs();

    try {
      // Initialize property groups
      log.info("*** Initialize property groups... ***");
      FormUtils.parsePropertyGroupsForms(Config.PROPERTY_GROUPS_XML);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }

    // Initialize language detection engine
    try {
      log.info("*** Initialize language detection engine... ***");
      DetectorFactory.loadProfile(Config.LANG_PROFILES_BASE);
    } catch (LangDetectException e) {
      log.error(e.getMessage(), e);
    }

    // Load database configuration
    Config.reload(sc, config);

    // Invoke start
    start();

    // Activity log
    UserActivity.log(Config.SYSTEM_USER, "MISC_OPENKM_START", null, null, null);
  }
  @BeforeClass
  public static void routeLoggingToSlf4j() {
    //		LogUtil.readJavaUtilLoggingConfigFromClasspath();
    /*remove loggers of jdk1.4*/
    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (int i = 0; i < handlers.length; i++) {
      rootLogger.removeHandler(handlers[i]);
    }
    /*end*/

    // direct logs of jdk1.4 to slf4j
    SLF4JBridgeHandler.install();
  }
예제 #11
0
  @Override
  public void contextInitialized(final ServletContextEvent event) {
    // we first remove the default handler(s)
    final Logger rootLogger = LogManager.getLogManager().getLogger("");
    final Handler[] handlers = rootLogger.getHandlers();

    if (!ArrayUtils.isEmpty(handlers)) {
      for (final Handler handler : handlers) {
        rootLogger.removeHandler(handler);
      }
    }
    // and then we let jul-to-sfl4j do its magic so that jersey messages go to sfl4j (and thus
    // log4j)
    SLF4JBridgeHandler.install();

    log.info("Assimilated java.util Logging");
  }
예제 #12
0
 @BeforeClass
 public static void staticSetup() {
   SLF4JBridgeHandler.removeHandlersForRootLogger();
   SLF4JBridgeHandler.install();
 }
예제 #13
0
  /** Initialize the logging subsystem and necessary logging bridges */
  public static void initialize() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();

    logger.info("JUL to SLF4J bridge initialized");
  }
예제 #14
0
파일: NiFi.java 프로젝트: RajiMenon/nifi
  public NiFi(final NiFiProperties properties)
      throws ClassNotFoundException, IOException, NoSuchMethodException, InstantiationException,
          IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Thread.setDefaultUncaughtExceptionHandler(
        new UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(final Thread t, final Throwable e) {
            logger.error("An Unknown Error Occurred in Thread {}: {}", t, e.toString());
            logger.error("", e);
          }
        });

    // register the shutdown hook
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    // shutdown the jetty server
                    shutdownHook();
                  }
                }));

    final String bootstrapPort = System.getProperty(BOOTSTRAP_PORT_PROPERTY);
    if (bootstrapPort != null) {
      try {
        final int port = Integer.parseInt(bootstrapPort);

        if (port < 1 || port > 65535) {
          throw new RuntimeException(
              "Failed to start NiFi because system property '"
                  + BOOTSTRAP_PORT_PROPERTY
                  + "' is not a valid integer in the range 1 - 65535");
        }

        bootstrapListener = new BootstrapListener(this, port);
        bootstrapListener.start();
      } catch (final NumberFormatException nfe) {
        throw new RuntimeException(
            "Failed to start NiFi because system property '"
                + BOOTSTRAP_PORT_PROPERTY
                + "' is not a valid integer in the range 1 - 65535");
      }
    } else {
      logger.info(
          "NiFi started without Bootstrap Port information provided; will not listen for requests from Bootstrap");
      bootstrapListener = null;
    }

    // delete the web working dir - if the application does not start successfully
    // the web app directories might be in an invalid state. when this happens
    // jetty will not attempt to re-extract the war into the directory. by removing
    // the working directory, we can be assured that it will attempt to extract the
    // war every time the application starts.
    File webWorkingDir = properties.getWebWorkingDirectory();
    FileUtils.deleteFilesInDirectory(webWorkingDir, null, logger, true, true);
    FileUtils.deleteFile(webWorkingDir, logger, 3);

    detectTimingIssues();

    // redirect JUL log events
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();

    // expand the nars
    final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties);

    // load the extensions classloaders
    NarClassLoaders.getInstance()
        .init(
            properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory());

    // load the framework classloader
    final ClassLoader frameworkClassLoader =
        NarClassLoaders.getInstance().getFrameworkClassLoader();
    if (frameworkClassLoader == null) {
      throw new IllegalStateException("Unable to find the framework NAR ClassLoader.");
    }

    // discover the extensions
    ExtensionManager.discoverExtensions(NarClassLoaders.getInstance().getExtensionClassLoaders());
    ExtensionManager.logClassLoaderMapping();

    DocGenerator.generate(properties);

    // load the server from the framework classloader
    Thread.currentThread().setContextClassLoader(frameworkClassLoader);
    Class<?> jettyServer =
        Class.forName("org.apache.nifi.web.server.JettyServer", true, frameworkClassLoader);
    Constructor<?> jettyConstructor = jettyServer.getConstructor(NiFiProperties.class);

    final long startTime = System.nanoTime();
    nifiServer = (NiFiServer) jettyConstructor.newInstance(properties);
    nifiServer.setExtensionMapping(extensionMapping);

    if (shutdown) {
      logger.info("NiFi has been shutdown via NiFi Bootstrap. Will not start Controller");
    } else {
      nifiServer.start();

      if (bootstrapListener != null) {
        bootstrapListener.sendStartedStatus(true);
      }

      final long endTime = System.nanoTime();
      logger.info("Controller initialization took " + (endTime - startTime) + " nanoseconds.");
    }
  }
 static {
   SLF4JBridgeHandler.removeHandlersForRootLogger();
   SLF4JBridgeHandler.install();
 }
예제 #16
0
 // Spring在所有属性注入后自动执行的函数.
 @PostConstruct
 public void init() {
   SLF4JBridgeHandler.install();
 }
예제 #17
0
 @Override
 public void contextDestroyed(final ServletContextEvent event) {
   SLF4JBridgeHandler.uninstall();
 }