Java Code Examples for org.apache.logging.log4j.core.config.Configurator#setAllLevels()

The following examples show how to use org.apache.logging.log4j.core.config.Configurator#setAllLevels() . 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: DSWorkbenchSplashScreen.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
public void initializeSuperSpecialDebugFeatures() {
    if (SPECIAL_DEBUG_MODE) {
        return;
    }
    SystrayHelper.showInfoMessage("Switching to debug mode");
    deadlockDetector = new ThreadDeadlockDetector();
    deadlockDetector.addListener(new DefaultDeadlockListener());
    Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.DEBUG);
    logger.debug("==========================");
    logger.debug("==DEBUG MODE ESTABLISHED==");
    logger.debug("==========================");

    logger.debug("---------System Information---------");
    logger.debug("Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + "/" + System.getProperty("os.arch") + ")");
    logger.debug("Java: " + System.getProperty("java.vendor") + " " + System.getProperty("java.version") + " (" + System.getProperty("java.home") + ")");
    logger.debug("Working Dir: " + System.getProperty("user.dir"));
    logger.debug("------------------------------------");
    SPECIAL_DEBUG_MODE = true;
}
 
Example 2
Source File: LoggerTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void debugChangeLevelAllChildrenLoggers() {
    // Use logger AND child loggers
    logger.debug("Debug message 1");
    loggerChild.debug("Debug message 1 child");
    loggerGrandchild.debug("Debug message 1 grandchild");
    assertEventCount(app.getEvents(), 3);
    Configurator.setAllLevels(logger.getName(), Level.OFF);
    logger.debug("Debug message 2");
    loggerChild.warn("Warn message 2 child");
    loggerGrandchild.fatal("Fatal message 2 grandchild");
    assertEventCount(app.getEvents(), 3);
    Configurator.setAllLevels(logger.getName(), Level.DEBUG);
    logger.debug("Debug message 3");
    loggerChild.warn("Trace message 3 child");
    loggerGrandchild.trace("Fatal message 3 grandchild");
    assertEventCount(app.getEvents(), 5);
}
 
Example 3
Source File: SignerSubCommand.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws TransactionSignerInitializationException {

  validateArgs();

  // set log level per CLI flags
  System.out.println("Setting logging level to " + config.getLogLevel().name());
  Configurator.setAllLevels("", config.getLogLevel());

  LOG.debug("Configuration = {}", this);
  LOG.info("Version = {}", ApplicationInfo.version());

  final EthSigner signer = new EthSigner(config, createSignerFactory());
  signer.run();
}
 
Example 4
Source File: RetestethSubCommand.java    From besu with Apache License 2.0 5 votes vote down vote up
private void prepareLogging() {
  // set log level per CLI flags
  if (logLevel != null) {
    System.out.println("Setting logging level to " + logLevel.name());
    Configurator.setAllLevels("", logLevel);
  }
}
 
Example 5
Source File: BesuCommand.java    From besu with Apache License 2.0 5 votes vote down vote up
public void configureLogging(final boolean announce) {
  // set log level per CLI flags
  if (logLevel != null) {
    if (announce) {
      System.out.println("Setting logging level to " + logLevel.name());
    }
    Configurator.setAllLevels("", logLevel);
  }
}
 
Example 6
Source File: Initialize.java    From kruize with Apache License 2.0 5 votes vote down vote up
public static void setup_deployment_info() throws Exception
{
    String cluster_type = System.getenv("CLUSTER_TYPE");
    String monitoring_agent_endpoint = System.getenv("MONITORING_AGENT_ENDPOINT");
    String monitoring_agent_service = System.getenv("MONITORING_SERVICE");
    String auth_token = System.getenv("AUTH_TOKEN");

    Defaults defaults  = AbstractDefaults.getInstance(cluster_type);

    String k8S_type = getEnv("K8S_TYPE", defaults.getK8sType());
    String auth_type = getEnv("AUTH_TYPE", defaults.getAuthType());
    String monitoring_agent = getEnv("MONITORING_AGENT", defaults.getMonitoringAgent());
    String logging_level = getEnv("LOGGING_LEVEL", defaults.getDebugLevel());

    DeploymentInfo.setClusterType(cluster_type);
    DeploymentInfo.setKubernetesType(k8S_type);
    DeploymentInfo.setAuthType(auth_type);
    DeploymentInfo.setMonitoringAgent(monitoring_agent);
    DeploymentInfo.setAuthToken(auth_token);
    DeploymentInfo.setMonitoringAgentEndpoint(monitoring_agent_endpoint);
    DeploymentInfo.setMonitoringAgentService(monitoring_agent_service);

    /* Initialization done successfully */
    HealthService.setCurrentStatus(HealthService.STATUS_UP);

    /* Update logging level from the env */
    Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.toLevel(logging_level));

    DeploymentInfo.logDeploymentInfo();
}
 
Example 7
Source File: AdminChangeLogLevel.java    From besu with Apache License 2.0 4 votes vote down vote up
private void setLogLevel(final String logFilter, final Level logLevel) {
  LOG.log(Level.OFF, "Setting {} logging level to {} ", logFilter, logLevel.name());
  Configurator.setAllLevels(logFilter, logLevel);
}
 
Example 8
Source File: AdminChangeLogLevelTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Before
public void before() {
  adminChangeLogLevel = new AdminChangeLogLevel();
  Configurator.setAllLevels("", Level.INFO);
}
 
Example 9
Source File: Service.java    From xyz-hub with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleAtDestination() {
  logger.info("LOG LEVEL UPDATE requested. New level will be: " + level);
  Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.getLevel(level));
  logger.info("LOG LEVEL UPDATE performed. New level is now: " + level);
}
 
Example 10
Source File: LoggingConfigurator.java    From teku with Apache License 2.0 4 votes vote down vote up
public static synchronized void setAllLevels(final Level level) {
  StatusLogger.getLogger().info("Setting logging level to {}", level.name());
  Configurator.setAllLevels("", level);
  ROOT_LOG_LEVEL = level;
}
 
Example 11
Source File: LoggingConfigurator.java    From teku with Apache License 2.0 4 votes vote down vote up
public static synchronized void setAllLevels(final String filter, final Level level) {
  StatusLogger.getLogger().info("Setting logging level on filter {} to {}", filter, level.name());
  Configurator.setAllLevels(filter, level);
}
 
Example 12
Source File: ApsSystemUtils.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void init() throws Exception {
    String active = (String) this.systemParams.get(INIT_PROP_LOG_ACTIVE_FILE_OUTPUT);
    if (StringUtils.isEmpty(active) || !active.equalsIgnoreCase("true")) {
        return;
    }
    String appenderName = "ENTANDO";
    String conversionPattern = (String) this.systemParams.get("log4jConversionPattern");
    if (StringUtils.isBlank(conversionPattern)) {
        conversionPattern = "%d{yyyy-MM-dd HH:mm:ss.SSS} - %-5p -  %c - %m%n";
    }
    String maxFileSize = (String) this.systemParams.get(INIT_PROP_LOG_FILE_SIZE);
    if (StringUtils.isBlank(maxFileSize)) {
        maxFileSize = "1MB"; //default size
    } else {
        long mega = new Long(maxFileSize) / KILOBYTE;
        maxFileSize = mega + "KB";
    }
    String filePattern = (String) this.systemParams.get(INIT_PROP_LOG_FILE_PATTERN);
    String filename = (String) this.systemParams.get(INIT_PROP_LOG_NAME);
    int maxBackupIndex = Integer.parseInt((String) this.systemParams.get(INIT_PROP_LOG_FILES_COUNT));
    String log4jLevelString = (String) this.systemParams.get(INIT_PROP_LOG_LEVEL);
    if (StringUtils.isBlank(log4jLevelString)) {
        log4jLevelString = "INFO"; //default level
    }
    Configurator.setRootLevel(Level.getLevel(log4jLevelString));
    LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    loggerContext.getRootLogger().setLevel(Level.getLevel(log4jLevelString));
    Configurator.setAllLevels(loggerContext.getRootLogger().getName(), Level.getLevel(log4jLevelString));
    Configuration configuration = loggerContext.getConfiguration();
    RollingFileAppender fileAppender = (RollingFileAppender) configuration.getAppender(appenderName);
    if (null == fileAppender) {
        PathCondition[] pathConditions = new PathCondition[]{IfAccumulatedFileCount.createFileCountCondition(maxBackupIndex)};
        String basePath = filePattern.substring(0, filePattern.lastIndexOf(File.separator));
        DeleteAction deleteAction = DeleteAction.createDeleteAction(basePath, true, 1, false, null, pathConditions, null, configuration);
        SizeBasedTriggeringPolicy policy = SizeBasedTriggeringPolicy.createPolicy(maxFileSize);
        PatternLayout layout = PatternLayout.newBuilder().withPattern(conversionPattern).build();
        DefaultRolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
                .withConfig(configuration).withMax(String.valueOf(maxBackupIndex))
                .withCustomActions(new Action[]{deleteAction}).build();
        fileAppender = RollingFileAppender.newBuilder()
                .withName(appenderName)
                .setConfiguration(configuration)
                .withLayout(layout)
                .withFileName(filename)
                .withFilePattern(filePattern)
                .withPolicy(policy)
                .withStrategy(strategy)
                .build();
        configuration.addAppender(fileAppender);
        Configurator.setLevel(appenderName, Level.getLevel(log4jLevelString));
        fileAppender.start();
    }
    AsyncAppender async = (AsyncAppender) loggerContext.getRootLogger().getAppenders().get("async");
    if (null == async) {
        AppenderRef ref = AppenderRef.createAppenderRef(appenderName, Level.getLevel(log4jLevelString), null);
        async = AsyncAppender.newBuilder().setName("async")
                .setConfiguration(configuration)
                .setAppenderRefs(new AppenderRef[]{ref}).build();
        configuration.addAppender(async);
        loggerContext.getRootLogger().addAppender(async);
        async.start();
    }
    loggerContext.updateLoggers();
}
 
Example 13
Source File: LoggerUtil.java    From blynk-server with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets desired log level from properties.
 *
 * @param level - desired log level. error|info|debug|trace, etc.
 */
private static void changeLogLevel(String level) {
    Level newLevel = Level.valueOf(level);
    Configurator.setAllLevels(LogManager.getRootLogger().getName(), newLevel);
}