Java Code Examples for org.slf4j.bridge.SLF4JBridgeHandler#removeHandlersForRootLogger()

The following examples show how to use org.slf4j.bridge.SLF4JBridgeHandler#removeHandlersForRootLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerTest.java    From raml-tester with Apache License 2.0 6 votes vote down vote up
@Before
public void initImpl() throws LifecycleException, ServletException {
    if (!inited.contains(getClass())) {
        inited.add(getClass());
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        tomcat = new Tomcat();
        tomcat.setPort(PORT);
        tomcat.setBaseDir(".");
        final Context ctx = tomcat.addWebapp("", "src/test");
        ctx.setJarScanner(NO_SCAN);
        ((Host) ctx.getParent()).setAppBase("");

        init(ctx);

        tomcat.start();
    }
}
 
Example 2
Source File: Util.java    From tessera with Apache License 2.0 6 votes vote down vote up
public static JerseyTest create(Enclave enclave) {

        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        return new JerseyTest() {
            @Override
            protected Application configure() {
                
                enable(TestProperties.LOG_TRAFFIC);
                enable(TestProperties.DUMP_ENTITY);
                set(TestProperties.CONTAINER_PORT, SocketUtils.findAvailableTcpPort());
                EnclaveApplication application = new EnclaveApplication(new EnclaveResource(enclave));

                ResourceConfig config = ResourceConfig.forApplication(application);
                config.packages("com.quorum.tessera.enclave.rest");
                return config;
            }

        };
    }
 
Example 3
Source File: JulBridge.java    From xio with Apache License 2.0 5 votes vote down vote up
public static synchronized void initialize() {
  if (dummy == -1) {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    dummy = 0;
  }
}
 
Example 4
Source File: AutodetectLogManager.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private AutodetectLogManager() {
    if (isLogbackInUse()) {
        logManager = new LogbackLogManager();
    } else {
        logManager = new NoOpLogManager();
    }

    try {
        java.util.logging.LogManager.getLogManager().reset();
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
    } catch (Exception e) {
        System.err.println("Unable to install JUL to SLF4J bridge");
    }
}
 
Example 5
Source File: Startup.java    From db with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
     * Method starts the database package and it's libraries by loading all their bean factories each of which is
     * responsible to load it's own code henceforth.
     *
     * List of bean factories is maintained under {@code /src/main/resources/launcher-config.xml}.
     *
     * TODO: 1) I had a dream.. a dream that some day main functions will parse CLI arguments.
     *
     * @param args who cares.. for now..
     */
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        logger.info("Starting BlobCity DB\"");

        // Pre-startup tasks below
        logger.debug("Configuring JUL Loggers");

        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        System.setProperty("jna.debug_load", "true");
        System.setProperty("jna.debug_load.jna", "true");

//        System.setProperty("java.library.path", "/lib");
        System.setProperty("jna.library.path", "/lib64");

        // Startup tasks below
        logger.debug("Performing database launch tasks");
        try {
            loadBeanConfigs(); // This task launches the database

            // Any other future tasks can go here as method class
            initEngine();
        } catch (ClassNotFoundException ex) {
            logger.error("Launching BlobCity DB has failed!", ex);
        }
        logger.info("BlobCity DB successfully started in " + (System.currentTimeMillis() - startTime) / 1000 + " seconds");

        logger.info("Setting log level to ERROR. Change by using set-log-level {log_level} CLI command");

        LogManager.getRootLogger().setLevel(org.apache.log4j.Level.ERROR);
        // it is assumed that startup failures are managed and appropriate logs are generated
    }
 
Example 6
Source File: GraviteeApisContainer.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeLogging() {
    super.initializeLogging();
    
    // Move all java util logging logs to SLF4j
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 7
Source File: Component.java    From clouditor with Apache License 2.0 5 votes vote down vote up
public Component() {
  this.locator = ServiceLocatorUtilities.createAndPopulateServiceLocator();
  ServiceLocatorUtilities.addOneConstant(this.locator, this);

  // Optionally remove existing handlers attached to j.u.l root logger
  SLF4JBridgeHandler.removeHandlersForRootLogger();

  // add SLF4JBridgeHandler to java.util.logging's root logger
  SLF4JBridgeHandler.install();
}
 
Example 8
Source File: AbstractPitMojo.java    From pitest with Apache License 2.0 5 votes vote down vote up
private void switchLogging() {
  if (this.useSlf4j) {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    Logger.getLogger("PIT").addHandler(new SLF4JBridgeHandler());
    SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
  }
}
 
Example 9
Source File: ServiceMain.java    From helios with Apache License 2.0 5 votes vote down vote up
protected static void setupLogging(LoggingConfig config, String sentryDsn) {
  if (config.getNoLogSetup()) {
    return;
  }

  // Hijack JUL
  SLF4JBridgeHandler.removeHandlersForRootLogger();
  SLF4JBridgeHandler.install();

  final int verbose = config.getVerbosity();
  final Level level = get(asList(INFO, DEBUG, ALL), verbose, ALL);
  final File logconfig = config.getConfigFile();

  if (logconfig != null) {
    LoggingConfigurator.configure(logconfig);
  } else {
    if (config.isSyslog()) {
      LoggingConfigurator.configureSyslogDefaults("helios", level);
    } else {
      LoggingConfigurator.configureDefaults("helios", level);
    }

    if (!Strings.isNullOrEmpty(sentryDsn)) {
      LoggingConfigurator.addSentryAppender(sentryDsn);
    }
  }
}
 
Example 10
Source File: Activator.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void start ( final BundleContext arg0 ) throws Exception
{
    SLF4JBridgeHandler.removeHandlersForRootLogger ();
    SLF4JBridgeHandler.install ();
}
 
Example 11
Source File: Preferences.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Reconfigure logging configuration
 *
 * @param level Log level
 */
public void setLogging(final String level) {
    this.setProperty("logging", level);
    // Call only once during initialization time of your application
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    // Apply default configuration
    final URL configuration;
    final String file = this.getDefault("logging.config");
    if(null == file) {
        configuration = Preferences.class.getClassLoader().getResource("log4j.xml");
    }
    else {
        configuration = Preferences.class.getClassLoader().getResource(file);
    }
    LogManager.resetConfiguration();
    final Logger root = Logger.getRootLogger();
    if(null != configuration) {
        DOMConfigurator.configure(configuration);
    }
    // Allow to override default logging level
    root.setLevel(Level.toLevel(level, Level.ERROR));
    // Map logging level to pass through bridge
    final ImmutableMap<Level, java.util.logging.Level> map = new ImmutableMap.Builder<Level, java.util.logging.Level>()
        .put(Level.ALL, java.util.logging.Level.ALL)
        .put(Level.DEBUG, java.util.logging.Level.FINE)
        .put(Level.ERROR, java.util.logging.Level.SEVERE)
        .put(Level.FATAL, java.util.logging.Level.SEVERE)
        .put(Level.INFO, java.util.logging.Level.INFO)
        .put(Level.OFF, java.util.logging.Level.OFF)
        .put(Level.TRACE, java.util.logging.Level.FINEST)
        .put(Level.WARN, java.util.logging.Level.WARNING)
        .build();
    java.util.logging.Logger.getLogger("").setLevel(map.get(root.getLevel()));
    final Enumeration loggers = LogManager.getCurrentLoggers();
    while(loggers.hasMoreElements()) {
        final Logger logger = (Logger) loggers.nextElement();
        if(logger.getLevel() != null) {
            java.util.logging.Logger.getLogger(logger.getName()).setLevel(map.get(logger.getLevel()));
        }
    }
}
 
Example 12
Source File: JulHandler.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void afterPropertiesSet() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 13
Source File: OpenShiftServiceImplTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 14
Source File: MuteJUL.java    From barge with Apache License 2.0 4 votes vote down vote up
@Override
protected void before() throws Throwable {
  Logger.getLogger("").setLevel(Level.ALL);
  SLF4JBridgeHandler.removeHandlersForRootLogger();
  SLF4JBridgeHandler.install();
}
 
Example 15
Source File: HeroicLogging.java    From heroic with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize java.util.logging to SLF4J.
 */
private static void configureJUL() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 16
Source File: LogbackConfiguration.java    From IridiumApplicationTesting with MIT License 4 votes vote down vote up
@Override
public void configureLogging(@NotNull final String logfile) {
	checkArgument(StringUtils.isNotBlank(logfile));

	try {
		final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

		final FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
		fileAppender.setContext(loggerContext);
		fileAppender.setName("timestamp");
		// set the file name
		fileAppender.setFile(logfile);

		final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
		encoder.setContext(loggerContext);
		encoder.setPattern("%r %thread %level - %msg%n");
		encoder.start();

		fileAppender.setEncoder(encoder);
		fileAppender.start();

		// attach the rolling file appender to the logger of your choice
		final Logger logbackLogger =
			(Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
		logbackLogger.addAppender(fileAppender);

		/*
			We only want to hear about errors from the libraries that are used by Iridium
		 */
		logbackLogger.setLevel(Level.ERROR);

		/*
			Our own code should be info level
		 */
		final Logger iridiumLogger =
			(Logger) LoggerFactory.getLogger("au.com.agic");
		iridiumLogger.setLevel(Level.INFO);

		/*
			Performance increase for redirected JUL loggers
		 */
		final LevelChangePropagator levelChangePropagator = new LevelChangePropagator();
		levelChangePropagator.setContext(loggerContext);
		levelChangePropagator.setResetJUL(true);
		loggerContext.addListener(levelChangePropagator);

		/*
			Redirect java logging and sys out to slf4j
		 */
		LogManager.getLogManager().reset();
		SLF4JBridgeHandler.removeHandlersForRootLogger();
		SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
		SLF4JBridgeHandler.install();
	} catch (final Exception ex) {
		LOGGER.error("WEBAPPTESTER-BUG-0006: Could not configure Logback", ex);
	}
}
 
Example 17
Source File: AsciidocEngine.java    From helidon-build-tools with Apache License 2.0 4 votes vote down vote up
/**
 * Setup the SLF4J to JUL bridge.
 */
private static void installSLF4JBridge(){
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 18
Source File: LoggingFactory.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
private void hijackJDKLogging() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 19
Source File: ReportPrinterTest.java    From analysis-model with MIT License 4 votes vote down vote up
@BeforeAll
static void beforeAll() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example 20
Source File: LoggingBootstrap.java    From hivemq-community-edition with Apache License 2.0 2 votes vote down vote up
/**
 * Redirects all logging statements from java.util.logging to SLF4J
 * <p>
 * This is needed because we may have many dependencies which rely on JUL.
 */
private static void redirectJULToSLF4J() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}