public void uninstall() { LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); loggerContext.getConfiguration().removeLogger(category); loggerContext.updateLoggers(); }
public static void main(String[] args) { try { final String nodeId = ConfigUtils.getOptionValue(args, NCConfig.Option.NODE_ID); final ConfigManager configManager = new ConfigManager(args); INCApplication application = getApplication(args); application.registerConfig(configManager); NCConfig ncConfig = new NCConfig(nodeId, configManager); LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration cfg = ctx.getConfiguration(); NCLogConfigurationFactory logCfgFactory = new NCLogConfigurationFactory(ncConfig); ConfigurationFactory.setConfigurationFactory(logCfgFactory); configManager.processConfig(); cfg.removeLogger("Console"); ctx.start(logCfgFactory.getConfiguration(ctx, ConfigurationSource.NULL_SOURCE)); final NodeControllerService ncService = new NodeControllerService(ncConfig, application); ncService.start(); while (true) { Thread.sleep(10000); } } catch (CmdLineException e) { LOGGER.log(Level.DEBUG, "Exception parsing command line: " + Arrays.toString(args), e); System.exit(2); } catch (Exception e) { LOGGER.error("Exiting NCDriver due to exception", e); System.exit(1); } }
public static void main(String[] args) throws Exception { try { final ConfigManager configManager = new ConfigManager(args); ICCApplication application = getApplication(args); application.registerConfig(configManager); CCConfig ccConfig = new CCConfig(configManager); LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration cfg = ctx.getConfiguration(); CCLogConfigurationFactory logCfgFactory = new CCLogConfigurationFactory(ccConfig); ConfigurationFactory.setConfigurationFactory(logCfgFactory); cfg.removeLogger("Console"); configManager.processConfig(); ctx.start(logCfgFactory.getConfiguration(ctx, ConfigurationSource.NULL_SOURCE)); ClusterControllerService ccService = new ClusterControllerService(ccConfig, application); ccService.start(); while (true) { Thread.sleep(100000); } } catch (CmdLineException e) { LOGGER.log(Level.DEBUG, "Exception parsing command line: " + Arrays.toString(args), e); System.exit(2); } catch (Exception e) { LOGGER.log(Level.ERROR, "Exiting CCDriver due to exception", e); System.exit(1); } }
public static void setAppender() { LoggerContext ctx = (LoggerContext) LogManager.getContext(true); org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration(); // If the event logger already exists, do nothing if (config.getLoggers().containsKey(LOGGERNAME)) { return; } Layout<String> layout = PatternLayout.newBuilder().withPattern("%msg%n").withConfiguration(config).build(); Appender jsonappender = ConsoleAppender.newBuilder() .withName(APPENDERNAME) .setTarget(ConsoleAppender.Target.SYSTEM_ERR) .withLayout(layout) .setConfiguration(config) .build(); jsonappender.start(); config.addAppender(jsonappender); AppenderRef ref = AppenderRef.createAppenderRef(APPENDERNAME, null, null); LoggerConfig loggerConfig = LoggerConfig.createLogger(false, LOGLEVEL, LOGGERNAME, "false", new AppenderRef[] {ref}, new Property[]{}, config, (Filter) null); loggerConfig.addAppender(jsonappender, null, null); config.removeLogger(LOGGERNAME); config.addLogger(LOGGERNAME, loggerConfig); ctx.updateLoggers(); } }