Java Code Examples for org.apache.log4j.BasicConfigurator#resetConfiguration()

The following examples show how to use org.apache.log4j.BasicConfigurator#resetConfiguration() . 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: SimpleEVCacheTest.java    From EVCache with Apache License 2.0 6 votes vote down vote up
@BeforeSuite
public void setProps() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{HH:mm:ss,SSS} [%t] %p %c %x - %m%n")));
    Logger.getRootLogger().setLevel(Level.INFO);
    Logger.getLogger(SimpleEVCacheTest.class).setLevel(Level.DEBUG);
    Logger.getLogger(Base.class).setLevel(Level.DEBUG);
    Logger.getLogger(EVCacheImpl.class).setLevel(Level.DEBUG);
    Logger.getLogger(EVCacheClient.class).setLevel(Level.DEBUG);
    Logger.getLogger(EVCacheClientPool.class).setLevel(Level.DEBUG);

    final Properties props = getProps();
    props.setProperty("EVCACHE_TEST.use.simple.node.list.provider", "true");
    props.setProperty("EVCACHE_TEST.EVCacheClientPool.readTimeout", "1000");
    props.setProperty("EVCACHE_TEST.EVCacheClientPool.bulkReadTimeout", "1000");
    props.setProperty("EVCACHE_TEST.max.read.queue.length", "100");
    props.setProperty("EVCACHE_TEST.operation.timeout", "10000");
    props.setProperty("EVCACHE_TEST.throw.exception", "false");

    int maxThreads = 2;
    final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(100000);
    pool = new ThreadPoolExecutor(maxThreads * 4, maxThreads * 4, 30, TimeUnit.SECONDS, queue);
    pool.prestartAllCoreThreads();
}
 
Example 2
Source File: PGMServer.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Logger setupLogger() {
  AnsiConsole.systemInstall();

  final java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
  global.setUseParentHandlers(false);

  final Handler[] handlers = global.getHandlers();
  for (int i = 0; i < handlers.length; ++i) {
    global.removeHandler(handlers[i]);
  }

  global.addHandler(new ForwardLogHandler());
  org.apache.logging.log4j.Logger logger = LogManager.getRootLogger();

  if (logger instanceof org.apache.logging.log4j.core.Logger) {
    final Iterator<org.apache.logging.log4j.core.Appender> appenders =
        ((org.apache.logging.log4j.core.Logger) logger).getAppenders().values().iterator();
    while (appenders.hasNext()) {
      final org.apache.logging.log4j.core.Appender appender = appenders.next();
      if (appender instanceof ConsoleAppender) {
        ((org.apache.logging.log4j.core.Logger) logger).removeAppender(appender);
      }
    }
  }

  new Thread(new TerminalConsoleWriterThread(System.out, reader)).start();
  System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
  System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));

  BasicConfigurator.resetConfiguration();

  try {
    return (Logger) PGMServer.class.getField("LOGGER").get(PGMServer.class);
  } catch (IllegalAccessException | NoSuchFieldException e) {
    // No-op
  }

  return logger;
}
 
Example 3
Source File: LogHelper.java    From openpojo with Apache License 2.0 5 votes vote down vote up
public static void initializeLog4J() {
  EventLogger.resetEvents(MockAppenderLog4J.class);
  BasicConfigurator.resetConfiguration();
  Properties props = new Properties();
  try {
    props.load(LogHelper.class.getResourceAsStream("/com/openpojo/utils/log/test.log4j.properties"));
  } catch (IOException e) {
    e.printStackTrace();
  }
  PropertyConfigurator.configure(props);
}
 
Example 4
Source File: LogHelper.java    From openpojo with Apache License 2.0 5 votes vote down vote up
public static void resetLoggers() {
  java.util.logging.LogManager.getLogManager().reset();

  BasicConfigurator.resetConfiguration();
  Properties props = new Properties();
  try {
    props.load(LogHelper.class.getResourceAsStream("/log4j.properties"));
  } catch (IOException e) {
    e.printStackTrace();
  }
  PropertyConfigurator.configure(props);
}
 
Example 5
Source File: TestStaxJobFactory.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void setJobDescriptorcUri() throws Exception {
    jobDescriptorUri = TestStaxJobFactory.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_update_variables.xml")
                                               .toURI();
    jobDescriptorNoVariablesUri = TestStaxJobFactory.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_no_variables.xml")
                                                          .toURI();
    jobDescriptorSysPropsUri = TestStaxJobFactory.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_update_variables_using_system_properties.xml")
                                                       .toURI();

    jobDescriptorWithMetadata = TestStaxJobFactory.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_with_metadata.xml")
                                                        .toURI();

    jobDescriptorWithEmptyMetadata = TestStaxJobFactory.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_with_empty_metadata.xml")
                                                             .toURI();

    jobDescriptorWithUnresolvedGenericInfoAndVariables = TestStaxJobFactory.class.getResource("job_with_unresolved_generic_info_and_variables.xml")
                                                                                 .toURI();

    jobDescriptorWithGlobalVariablesAndGenericInfo = TestStaxJobFactory.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_with_global_variables_and_gi.xml")
                                                                             .toURI();

    jobDescriptorAttrDefGenericInformationXmlElement = TestStaxJobFactory.class.getResource("job_attr_def_generic_information_xml_element.xml")
                                                                               .toURI();

    jobDescriptorAttrDefParameterXmlElement = TestStaxJobFactory.class.getResource("job_attr_def_parameter_xml_element.xml")
                                                                      .toURI();

    jobDescriptorAttrDefVariableXmlElement = TestStaxJobFactory.class.getResource("job_attr_def_variable_xml_element.xml")
                                                                     .toURI();

    jobDescriptorTaskVariable = TestStaxJobFactory.class.getResource("task_variables.xml").toURI();

    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
}
 
Example 6
Source File: TestLocalImhotepServiceCore.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initLog4j() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();

    final Layout LAYOUT = new PatternLayout("[ %d{ISO8601} %-5p ] [%c{1}] %m%n");

    LevelRangeFilter ERROR_FILTER = new LevelRangeFilter();
    ERROR_FILTER.setLevelMin(Level.ERROR);
    ERROR_FILTER.setLevelMax(Level.FATAL);

    // everything including ERROR
    final Appender STDOUT = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_OUT);

    // just things <= ERROR
    final Appender STDERR = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_ERR);
    STDERR.addFilter(ERROR_FILTER);

    final Logger ROOT_LOGGER = Logger.getRootLogger();

    ROOT_LOGGER.removeAllAppenders();

    ROOT_LOGGER.setLevel(Level.WARN); // don't care about higher

    ROOT_LOGGER.addAppender(STDOUT);
    ROOT_LOGGER.addAppender(STDERR);
}
 
Example 7
Source File: AbstractFTGSMergerCase.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initLog4j() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();

    final Layout LAYOUT = new PatternLayout("[ %d{ISO8601} %-5p ] [%c{1}] %m%n");

    LevelRangeFilter ERROR_FILTER = new LevelRangeFilter();
    ERROR_FILTER.setLevelMin(Level.ERROR);
    ERROR_FILTER.setLevelMax(Level.FATAL);

    // everything including ERROR
    final Appender STDOUT = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_OUT);

    // just things <= ERROR
    final Appender STDERR = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_ERR);
    STDERR.addFilter(ERROR_FILTER);

    final Logger ROOT_LOGGER = Logger.getRootLogger();

    ROOT_LOGGER.removeAllAppenders();

    ROOT_LOGGER.setLevel(Level.WARN); // don't care about higher

    ROOT_LOGGER.addAppender(STDOUT);
    ROOT_LOGGER.addAppender(STDERR);
}
 
Example 8
Source File: TestSimpleFlamdexDocWriter.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initLog4j() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();

    final Layout LAYOUT = new PatternLayout("[ %d{ISO8601} %-5p ] [%c{1}] %m%n");

    LevelRangeFilter ERROR_FILTER = new LevelRangeFilter();
    ERROR_FILTER.setLevelMin(Level.ERROR);
    ERROR_FILTER.setLevelMax(Level.FATAL);

    // everything including ERROR
    final Appender STDOUT = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_OUT);

    // just things <= ERROR
    final Appender STDERR = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_ERR);
    STDERR.addFilter(ERROR_FILTER);

    final Logger ROOT_LOGGER = Logger.getRootLogger();

    ROOT_LOGGER.removeAllAppenders();

    ROOT_LOGGER.setLevel(Level.WARN); // don't care about higher

    ROOT_LOGGER.addAppender(STDOUT);
    ROOT_LOGGER.addAppender(STDERR);
}
 
Example 9
Source File: DirectoriesTest.java    From util with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initClass() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.WARN);
    Logger.getLogger("com.indeed").setLevel(Level.DEBUG);
}
 
Example 10
Source File: SafeFilesTest.java    From util with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initClass() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.WARN);
    Logger.getLogger("com.indeed").setLevel(Level.DEBUG);
}
 
Example 11
Source File: ProbabilisticSelectionManagerTest.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    Logger.getLogger(ProbablisticSelectionManager.class).setLevel(Level.DEBUG);
}
 
Example 12
Source File: LostScheduledMessagesTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
   broker.stop();
   BasicConfigurator.resetConfiguration();
}
 
Example 13
Source File: ConnectionPoolHealthTrackerTest.java    From dyno with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass() {
    BasicConfigurator.resetConfiguration();
    threadPool.shutdownNow();
}
 
Example 14
Source File: AppLogService.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * initializes the errors log file and the application log file
 * 
 * @param strConfigPath
 *            The strConfigPath
 * @param strConfigFile
 *            The strConfigFile
 */
public static void init( String strConfigPath, String strConfigFile )
{
    BasicConfigurator.resetConfiguration( );
    // Initialize the logger and configures it with the values of the properties file : config.properties
    InputStream is = null;
    try
    {
        String strAbsoluteConfigDirectoryPath = AppPathService.getAbsolutePathFromRelativePath( strConfigPath );
        String strAlternateFilePath = strAbsoluteConfigDirectoryPath + ( strAbsoluteConfigDirectoryPath.endsWith( "/" ) ? "" : "/" )
                + ALTERNATE_LOG_OVERRIDE_PATH;

        File alternateLogFile = new File( strAlternateFilePath + File.separator + ALTERNATE_LOG_FILE );
        boolean bAlternateConfigFile = alternateLogFile.exists( );
        String strLog4jConfigFile;

        if ( bAlternateConfigFile )
        {
            // Load loggers configuration from the log.properties
            is = AppPathService.getResourceAsStream( strConfigPath + ( strConfigPath.endsWith( "/" ) ? "" : "/" ) + ALTERNATE_LOG_OVERRIDE_PATH + "/",
                    ALTERNATE_LOG_FILE );
            strLog4jConfigFile = alternateLogFile.getAbsolutePath( );
        }
        else
        {
            // Load loggers configuration from the config.properties
            is = AppPathService.getResourceAsStream( strConfigPath, strConfigFile );
            strLog4jConfigFile = strAbsoluteConfigDirectoryPath + ( ( strAbsoluteConfigDirectoryPath.endsWith( "/" ) ) ? "" : "/" ) + strConfigFile;
        }

        Properties props = new Properties( );
        props.load( is );
        PropertyConfigurator.configure( props );
        is.close( );

        // Define the config.properties as log4j configuration file for other libraries using
        // the System property "log4j.configuration"
        System.setProperty( SYSTEM_PROPERTY_LOG4J_CONFIGURATION, strLog4jConfigFile );

        if ( bAlternateConfigFile )
        {
            debug( "Loaded log properties from alternate log.properties file " );
        }
    }
    catch( Exception e )
    {
        error( "Bad Configuration of Log4j : " + e );
    }
    finally
    {
        StreamUtil.safeClose( is );
    }
    info( "Lutece logs initialized, using configured property files to define levels and appenders." );
}
 
Example 15
Source File: LogInitializer.java    From DataGenerator with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes log4j
 *
 * @param loggerLevel log level to initialize to
 */
public static void initialize(String loggerLevel) {
    if (!INIT.compareAndSet(false, true)) {
        return;
    }

    BasicConfigurator.resetConfiguration();
    ConsoleAppender consoleAppender = new ConsoleAppender(
        new PatternLayout("<%d{yyMMdd HHmmss} %5p %C{1}:%L> %m%n"), ConsoleAppender.SYSTEM_ERR);
    BasicConfigurator.configure(consoleAppender);

    Level level;

    String logLevel;

    if (loggerLevel != null) {
        logLevel = loggerLevel.toLowerCase();
    } else {
        logLevel = "default";
    }

    switch (logLevel) {
        case "all":
            level = Level.ALL;
            break;
        case "debug":
            level = Level.DEBUG;
            break;
        case "error":
            level = Level.ERROR;
            break;
        case "fatal":
            level = Level.FATAL;
            break;
        case "info":
            level = Level.INFO;
            break;
        case "off":
            level = Level.OFF;
            break;
        case "trace":
            level = Level.TRACE;
            break;
        case "warn":
            level = Level.WARN;
            break;
        default:
            level = Level.INFO;
            break;
    }

    Logger.getRootLogger().setLevel(Level.OFF);
    Logger.getLogger("org.finra").setLevel(level);

    System.err.println("Set loglevel to " + level.toString());
}