private static void clearLogContext(final LogContextConfiguration logContextConfiguration) { try { for (String name : logContextConfiguration.getLoggerNames()) { logContextConfiguration.removeLoggerConfiguration(name); for (String name : logContextConfiguration.getHandlerNames()) { logContextConfiguration.removeHandlerConfiguration(name); for (String name : logContextConfiguration.getFormatterNames()) { logContextConfiguration.removeFormatterConfiguration(name); for (String name : logContextConfiguration.getErrorManagerNames()) { logContextConfiguration.removeErrorManagerConfiguration(name); for (String name : logContextConfiguration.getPojoNames()) { logContextConfiguration.removePojoConfiguration(name); for (String name : logContextConfiguration.getFilterNames()) { logContextConfiguration.removeFilterConfiguration(name); logContextConfiguration.commit(); } finally { logContextConfiguration.forget();
@Override public void performRuntime(final OperationContext context, final ModelNode operation, final LogContextConfiguration logContextConfiguration, final String name, final ModelNode model) throws OperationFailedException { final String loggerName = getLogManagerLoggerName(name); LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName); if (configuration == null) { LoggingLogger.ROOT_LOGGER.tracef("Adding logger '%s' at '%s'", name, LoggingOperations.getAddress(operation)); configuration = logContextConfiguration.addLoggerConfiguration(loggerName); } for (AttributeDefinition attribute : attributes) { handleProperty(attribute, context, model, configuration); } } }
@Override public HandlerConfiguration getHandlerConfiguration(final String handlerName) { synchronized (LOCK) { return delegate.getHandlerConfiguration(handlerName); } }
@Override public void performRuntime(final OperationContext context, final ModelNode operation, final LogContextConfiguration logContextConfiguration, final String name, final ModelNode model) throws OperationFailedException { // Validating wouldn't work until the LogContextConfiguration.commit() happens as handlers could still be // named as attached removed the check for this reason. // Remove the handler logContextConfiguration.removeHandlerConfiguration(name); // Remove the formatter if there is one if (logContextConfiguration.getFormatterNames().contains(name)) { logContextConfiguration.removeFormatterConfiguration(name); } // Remove the POJO if it exists if (logContextConfiguration.getPojoNames().contains(name)) { logContextConfiguration.removePojoConfiguration(name); } } };
final Set<String> implicitFormatters = new HashSet<String>(); final Set<String> implicitErrorManagers = new HashSet<String>(); final List<String> loggerNames = config.getLoggerNames(); writePropertyComment(out, "Additional loggers to configure (the root logger is always configured)"); writeProperty(out, "loggers", toCsvString(loggerNames)); final LoggerConfiguration rootLogger = config.getLoggerConfiguration(""); writeLoggerConfiguration(out, rootLogger, implicitHandlers, implicitFilters, writeExpressions); writeLoggerConfiguration(out, config.getLoggerConfiguration(loggerName), implicitHandlers, implicitFilters, writeExpressions); final List<String> allHandlerNames = config.getHandlerNames(); final List<String> explicitHandlerNames = new ArrayList<String>(allHandlerNames); explicitHandlerNames.removeAll(implicitHandlers); writeHandlerConfiguration(out, config.getHandlerConfiguration(handlerName), implicitHandlers, implicitFilters, implicitFormatters, implicitErrorManagers, writeExpressions); final List<String> allFilterNames = config.getFilterNames(); final List<String> explicitFilterNames = new ArrayList<String>(allFilterNames); explicitFilterNames.removeAll(implicitFilters); writeFilterConfiguration(out, config.getFilterConfiguration(filterName), writeExpressions); final List<String> allFormatterNames = config.getFormatterNames(); final ArrayList<String> explicitFormatterNames = new ArrayList<String>(allFormatterNames); explicitFormatterNames.removeAll(implicitFormatters); writeFormatterConfiguration(out, config.getFormatterConfiguration(formatterName), writeExpressions);
final String name = context.getCurrentAddressValue(); final List<String> loggerNames = logContextConfiguration.getLoggerNames(); final List<String> assigned = new ArrayList<>(); for (String loggerName : loggerNames) { final LoggerConfiguration c = logContextConfiguration.getLoggerConfiguration(loggerName); if (c != null) { if (c.getHandlerNames().contains(name)) { final List<String> handlerNames = logContextConfiguration.getHandlerNames(); for (String handlerName : handlerNames) { final HandlerConfiguration c = logContextConfiguration.getHandlerConfiguration(handlerName); if (c != null) { if (c.getHandlerNames().contains(name)) { logContextConfiguration.removeHandlerConfiguration(name); if (logContextConfiguration.getFormatterNames().contains(name) && !model.hasDefined(NAMED_FORMATTER.getName())) { logContextConfiguration.removeFormatterConfiguration(name); if (logContextConfiguration.getPojoNames().contains(name)) { logContextConfiguration.removePojoConfiguration(name);
/** * Registers the deployment resources needed. * * @param deploymentResourceSupport the deployment resource support * @param service the service, which may be {@code null}, used to find the resource names that need to be registered */ public static void registerDeploymentResource(final DeploymentResourceSupport deploymentResourceSupport, final LoggingConfigurationService service) { final PathElement base = PathElement.pathElement("configuration", service.getConfiguration()); deploymentResourceSupport.getDeploymentSubModel(LoggingExtension.SUBSYSTEM_NAME, base); final LogContextConfiguration configuration = service.getValue(); // Register the child resources if the configuration is not null in cases where a log4j configuration was used if (configuration != null) { registerDeploymentResource(deploymentResourceSupport, base, HANDLER, configuration.getHandlerNames()); registerDeploymentResource(deploymentResourceSupport, base, LOGGER, configuration.getLoggerNames()); registerDeploymentResource(deploymentResourceSupport, base, FORMATTER, configuration.getFormatterNames()); registerDeploymentResource(deploymentResourceSupport, base, FILTER, configuration.getFilterNames()); registerDeploymentResource(deploymentResourceSupport, base, POJO, configuration.getPojoNames()); registerDeploymentResource(deploymentResourceSupport, base, ERROR_MANAGER, configuration.getErrorManagerNames()); } }
logContextConfiguration.removeLoggerConfiguration(CommonAttributes.ROOT_LOGGER_NAME); final List<String> configuredLoggerNames = logContextConfiguration.getLoggerNames(); for (String name : configuredLoggerNames) { LoggingLogger.ROOT_LOGGER.tracef("Removing logger configuration for '%s'", name); logContextConfiguration.removeLoggerConfiguration(name); final List<String> configuredHandlerNames = logContextConfiguration.getHandlerNames(); configuredHandlerNames.removeAll(subsystemHandlers); for (String name : configuredHandlerNames) { LoggingLogger.ROOT_LOGGER.tracef("Removing handler configuration for '%s'", name); logContextConfiguration.removePojoConfiguration(name); logContextConfiguration.removeHandlerConfiguration(name); final List<String> configuredFormatters = logContextConfiguration.getFormatterNames(); configuredFormatters.removeAll(resource.getChildrenNames(PatternFormatterResourceDefinition.NAME)); configuredFormatters.removeAll(resource.getChildrenNames(CustomFormatterResourceDefinition.NAME)); LoggingLogger.ROOT_LOGGER.tracef("Removing formatter configuration for '%s'", name); logContextConfiguration.removeFormatterConfiguration(name);
if (logContextConfiguration.getFormatterNames().contains(handlerName)) { logContextConfiguration.removeFormatterConfiguration(handlerName); if (logContextConfiguration.getFormatterNames().contains(handlerName)) { fmtConfig = logContextConfiguration.getFormatterConfiguration(handlerName); } else { fmtConfig = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), handlerName, PATTERN.getPropertyName()); configuration.setFormatterName(resolvedValue); if (logContextConfiguration.getFormatterNames().contains(handlerName)) { logContextConfiguration.removeFormatterConfiguration(handlerName); if (logContextConfiguration.getFormatterNames().contains(handlerName)) { fmtConfig = logContextConfiguration.getFormatterConfiguration(handlerName); } else { fmtConfig = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), handlerName, PATTERN.getPropertyName()); final PropertyConfigurable propertyConfigurable; final PojoConfiguration pojoConfiguration = logContextConfiguration.getPojoConfiguration(configuration.getName()); if (pojoConfiguration == null) { propertyConfigurable = configuration;
final Collection<String> handlersToRemove = config.getHandlerNames(); final Collection<String> loggersToRemove = config.getLoggerNames(); loggersToRemove.remove(""); loggersToRemove.removeAll(Arrays.asList(loggerNames)); for (String loggerName : loggersToRemove) { config.removeLoggerConfiguration(loggerName); config.removeHandlerConfiguration(handlerName); configurePojos(properties, pojoName); config.commit(); } finally { config.forget();
HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name); boolean replaceHandler = false; final boolean exists = configuration != null; final PojoConfiguration log4jPojo = logContextConfiguration.getPojoConfiguration(name); if (log4jPojo != null) { replaceHandler = (!className.equals(log4jPojo.getClassName()) || (moduleName == null ? log4jPojo.getModuleName() != null : !moduleName.equals(log4jPojo.getModuleName()))); logContextConfiguration.removeHandlerConfiguration(name); if (logContextConfiguration.getPojoNames().contains(name)) { logContextConfiguration.removePojoConfiguration(name);
@Override public void configure(InputStream inputStream) throws IOException { this.propertyConfigurator.configure(inputStream); LogContextConfiguration config = this.propertyConfigurator.getLogContextConfiguration(); config.getHandlerConfiguration("CONSOLE").setLevel("ALL"); LevelNode root = InitialLoggerManager.INSTANCE.getRoot(); apply(root, config); config.commit(); }
@Override protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException { boolean restartRequired = false; if (logContextConfiguration.getHandlerNames().contains(addressName)) { final HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(addressName); if (LEVEL.getName().equals(attributeName)) { handleProperty(LEVEL, context, value, logContextConfiguration, configuration, false); final PropertyConfigurable propertyConfigurable; final PojoConfiguration pojoConfiguration = logContextConfiguration.getPojoConfiguration(configuration.getName()); if (pojoConfiguration == null) { propertyConfigurable = configuration;
currentValue = Boolean.parseBoolean(configuration.getPropertyValueString(ENABLED.getPropertyName())); } else { currentValue = isDisabledHandler(logContextConfiguration.getLogContext(), configuration.getName()); if (logContextConfiguration.getFormatterNames().contains(formatterName)) { fmtConfig = logContextConfiguration.getFormatterConfiguration(formatterName); final String resolvedValue = FORMATTER.resolvePropertyValue(context, model); final String currentValue = fmtConfig.getPropertyValueString(PATTERN.getName()); final PropertyConfigurable propertyConfigurable; final PojoConfiguration pojoConfiguration = logContextConfiguration.getPojoConfiguration(configuration.getName()); if (pojoConfiguration == null) { propertyConfigurable = configuration;
logContextConfiguration.removeLoggerConfiguration(CommonAttributes.ROOT_LOGGER_NAME); final List<String> configuredLoggerNames = logContextConfiguration.getLoggerNames(); for (String name : configuredLoggerNames) { LoggingLogger.ROOT_LOGGER.tracef("Removing logger configuration for '%s'", name); logContextConfiguration.removeLoggerConfiguration(name); final List<String> configuredHandlerNames = logContextConfiguration.getHandlerNames(); configuredHandlerNames.removeAll(resource.getChildrenNames(AsyncHandlerResourceDefinition.ASYNC_HANDLER)); configuredHandlerNames.removeAll(resource.getChildrenNames(ConsoleHandlerResourceDefinition.CONSOLE_HANDLER)); for (String name : configuredHandlerNames) { LoggingLogger.ROOT_LOGGER.tracef("Removing handler configuration for '%s'", name); logContextConfiguration.removeHandlerConfiguration(name);
/** * Enables the handler if it was previously disabled. * <p/> * If it was not previously disable, nothing happens. * * @param configuration the log context configuration. * @param handlerName the name of the handler to enable. */ static void enableHandler(final LogContextConfiguration configuration, final String handlerName) { final HandlerConfiguration handlerConfiguration = configuration.getHandlerConfiguration(handlerName); try { handlerConfiguration.setPropertyValueString("enabled", "true"); return; } catch (IllegalArgumentException e) { // do nothing } final Map<String, String> disableHandlers = configuration.getLogContext().getAttachment(CommonAttributes.ROOT_LOGGER_NAME, DISABLED_HANDLERS_KEY); if (disableHandlers != null && disableHandlers.containsKey(handlerName)) { synchronized (HANDLER_LOCK) { final String filter = disableHandlers.get(handlerName); handlerConfiguration.setFilter(filter); disableHandlers.remove(handlerName); } } }
private List<String> configureLogger(final Properties properties, final String loggerName) { final LoggerConfiguration loggerConfiguration; if (config.getLoggerNames().contains(loggerName)) { loggerConfiguration = config.getLoggerConfiguration(loggerName); } else { loggerConfiguration = config.addLoggerConfiguration(loggerName);
if (formatterName != null) { if (config.getFormatterNames().contains(handler.getFormatterName())) { writeProperty(out, prefix, "formatter", formatterName); implicitFormatters.add(handler.getFormatterName()); if (errorManagerName != null) { if (config.getErrorManagerNames().contains(handler.getErrorManagerName())) { writeProperty(out, prefix, "errorManager", errorManagerName); implicitErrorManagers.add(handler.getErrorManagerName()); if (config.getHandlerNames().contains(handlerName)) { implicitHandlers.add(handlerName); handlerNames.add(handlerName);
@Override protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException { final String loggerName = getLogManagerLoggerName(addressName); if (logContextConfiguration.getLoggerNames().contains(loggerName)) { final LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName); if (LEVEL.getName().equals(attributeName)) { handleProperty(LEVEL, context, value, configuration, false); } else if (FILTER.getName().equals(attributeName)) { // Filter should be replaced by the filter-spec in the super class handleProperty(FILTER_SPEC, context, value, configuration, false); } else if (FILTER_SPEC.getName().equals(attributeName)) { handleProperty(FILTER_SPEC, context, value, configuration, false); } else if (HANDLERS.getName().equals(attributeName)) { handleProperty(HANDLERS, context, value, configuration, false); } else if (USE_PARENT_HANDLERS.getName().equals(attributeName)) { handleProperty(USE_PARENT_HANDLERS, context, value, configuration, false); } } return false; }
if (config.getHandlerNames().contains(handlerName)) { configuration = config.getHandlerConfiguration(handlerName); } else { configuration = config.addHandlerConfiguration(getStringProperty(properties, getKey(HANDLER, handlerName, MODULE)), className, handlerName, getStringCsvArray(properties, getKey(HANDLER, handlerName, CONSTRUCTOR_PROPERTIES)));