org.jboss.logmanager.config.LogContextConfiguration Java Examples

The following examples show how to use org.jboss.logmanager.config.LogContextConfiguration. 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: SocketHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name);
    if (configuration == null) {
        configuration = logContextConfiguration.addHandlerConfiguration(null, DelayedHandler.class.getName(), name);
    } else {
        if (!(configuration.getInstance() instanceof DelayedHandler)) {
            throw LoggingLogger.ROOT_LOGGER.invalidType(DelayedHandler.class, configuration.getInstance().getClass());
        }
    }
    ENABLED.setPropertyValue(context, model, configuration);
    final ModelNode filter = FILTER_SPEC.resolveModelAttribute(context, model);
    if (filter.isDefined()) {
        configuration.setFilter(filter.asString());
    }
    configuration.setLevel(LEVEL.resolvePropertyValue(context, model));
    configuration.setFormatterName(NAMED_FORMATTER.resolveModelAttribute(context, model).asString());
}
 
Example #2
Source File: HandlerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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.
 */
private 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);
        }
    }
}
 
Example #3
Source File: HandlerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Disables the handler if the handler exists and is not already disabled.
 * <p/>
 * If the handler does not exist or is already disabled nothing happens.
 *
 * @param configuration the log context configuration.
 * @param handlerName   the handler name to disable.
 */
private static void disableHandler(final LogContextConfiguration configuration, final String handlerName) {
    final HandlerConfiguration handlerConfiguration = configuration.getHandlerConfiguration(handlerName);
    try {
        handlerConfiguration.setPropertyValueString("enabled", "false");
        return;
    } catch (IllegalArgumentException e) {
        // do nothing
    }
    final Logger root = configuration.getLogContext().getLogger(CommonAttributes.ROOT_LOGGER_NAME);
    Map<String, String> disableHandlers = root.getAttachment(DISABLED_HANDLERS_KEY);
    synchronized (HANDLER_LOCK) {
        if (disableHandlers == null) {
            disableHandlers = new HashMap<String, String>();
            final Map<String, String> current = root.attachIfAbsent(DISABLED_HANDLERS_KEY, disableHandlers);
            if (current != null) {
                disableHandlers = current;
            }
        }
        if (!disableHandlers.containsKey(handlerName)) {
            disableHandlers.put(handlerName, handlerConfiguration.getFilter());
            handlerConfiguration.setFilter(CommonAttributes.DENY.getName());
        }
    }
}
 
Example #4
Source File: HandlerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.handlerConfigurationNotFound(name));
    }
    // Get the handler name, uses the operation to get the single handler name being added
    final String handlerName = HANDLER_NAME.resolveModelAttribute(context, operation).asString();
    if (name.equals(handlerName)) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.cannotAddHandlerToSelf(configuration.getName()));
    }
    if (configuration.getHandlerNames().contains(handlerName)) {
        LoggingLogger.ROOT_LOGGER.tracef("Handler %s is already assigned to handler %s", handlerName, handlerName);
    } else {
        configuration.addHandlerName(handlerName);
    }
}
 
Example #5
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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;
}
 
Example #6
Source File: CustomFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(addressName);
    String modelClass = CLASS.resolveModelAttribute(context, context.readResource(PathAddress.EMPTY_ADDRESS).getModel()).asString();
    if (PROPERTIES.getName().equals(attributeName) && configuration.getClassName().equals(modelClass)) {
        if (value.isDefined()) {
            for (Property property : value.asPropertyList()) {
                configuration.setPropertyValueString(property.getName(), property.getValue().asString());
            }
        } else {
            // Remove all current properties
            final List<String> names = configuration.getPropertyNames();
            for (String name : names) {
                configuration.removeProperty(name);
            }
        }
    }

    // Writing a class attribute or module will require the previous formatter to be removed and a new formatter
    // added. It's best to require a restart.
    return CLASS.getName().equals(attributeName) || MODULE.getName().equals(attributeName);
}
 
Example #7
Source File: CustomFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(name);
    final String className = CLASS.resolveModelAttribute(context, model).asString();
    final ModelNode moduleNameNode = MODULE.resolveModelAttribute(context, model);
    final String moduleName = moduleNameNode.isDefined() ? moduleNameNode.asString() : null;
    final ModelNode properties = PROPERTIES.resolveModelAttribute(context, model);
    if (configuration != null) {
        if (!className.equals(configuration.getClassName()) || (moduleName == null ? configuration.getModuleName() != null : !moduleName.equals(configuration.getModuleName()))) {
            LoggingLogger.ROOT_LOGGER.tracef("Replacing formatter '%s' at '%s'", name, context.getCurrentAddress());
            logContextConfiguration.removeFormatterConfiguration(name);
            configuration = logContextConfiguration.addFormatterConfiguration(moduleName, className, name);
        }
    } else {
        LoggingLogger.ROOT_LOGGER.tracef("Adding formatter '%s' at '%s'", name, context.getCurrentAddress());
        configuration = logContextConfiguration.addFormatterConfiguration(moduleName, className, name);
    }
    if (properties.isDefined()) {
        for (Property property : properties.asPropertyList()) {
            configuration.setPropertyValueString(property.getName(), property.getValue().asString());
        }
    }
}
 
Example #8
Source File: PatternFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    if (name.endsWith(DEFAULT_FORMATTER_SUFFIX)) {
        throw LoggingLogger.ROOT_LOGGER.illegalFormatterName();
    }
    FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(name);
    if (configuration == null) {
        LoggingLogger.ROOT_LOGGER.tracef("Adding formatter '%s' at '%s'", name, context.getCurrentAddress());
        configuration = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), name);
    }

    for (PropertyAttributeDefinition attribute : ATTRIBUTES) {
        attribute.setPropertyValue(context, model, configuration);
    }
}
 
Example #9
Source File: SocketHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected OperationStepHandler additionalModelStep(final LogContextConfiguration logContextConfiguration) {
    return new OperationStepHandler() {
        @Override
        public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
            // If we don't require runtime steps to be executed we need to discard records on the delayed handler
            if (!requiresRuntime(context)) {
                HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(context.getCurrentAddressValue());
                if (configuration != null) {
                    if (!(configuration.getInstance() instanceof DelayedHandler)) {
                        throw LoggingLogger.ROOT_LOGGER.invalidType(DelayedHandler.class, configuration.getInstance().getClass());
                    }
                    final DelayedHandler delayedHandler = (DelayedHandler) configuration.getInstance();
                    // Clear any previous handlers and close them, then add the new handler
                    final Handler[] current = delayedHandler.setHandlers(new Handler[] {new DiscardingHandler()});
                    if (current != null) {
                        for (Handler handler : current) {
                            handler.close();
                        }
                    }
                }
            }
        }
    };
}
 
Example #10
Source File: FilterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final FilterConfiguration configuration = logContextConfiguration.getFilterConfiguration(addressName);
    String modelClass = CLASS.resolveModelAttribute(context, context.readResource(PathAddress.EMPTY_ADDRESS).getModel()).asString();
    if (PROPERTIES.getName().equals(attributeName) && configuration.getClassName().equals(modelClass)) {
        if (value.isDefined()) {
            for (Property property : value.asPropertyList()) {
                configuration.setPropertyValueString(property.getName(), property.getValue().asString());
            }
        } else {
            // Remove all current properties
            final List<String> names = configuration.getPropertyNames();
            for (String name : names) {
                configuration.removeProperty(name);
            }
        }
    }

    // Writing a class attribute or module will require the previous filter to be removed and a new filter
    // added. This also would require each logger or handler that has the filter assigned to reassign the
    // filter. The configuration API does not handle this so a reload will be required.
    return CLASS.getName().equals(attributeName) || MODULE.getName().equals(attributeName) ||
            CONSTRUCTOR_PROPERTIES.getName().equals(attributeName);
}
 
Example #11
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void compare(final ModelNode currentModel, final ConfigurationPersistence config) throws OperationFailedException {
    final LogContextConfiguration logContextConfig = config.getLogContextConfiguration();
    final List<String> handlerNames = logContextConfig.getHandlerNames();
    final List<String> modelHandlerNames = getHandlerNames(currentModel);
    final List<String> missingConfigHandlers = new ArrayList<>(handlerNames);
    missingConfigHandlers.removeAll(modelHandlerNames);
    final List<String> missingModelHandlers = new ArrayList<>(modelHandlerNames);
    missingModelHandlers.removeAll(handlerNames);

    Assert.assertTrue("Configuration contains handlers not in the model: " + missingConfigHandlers, missingConfigHandlers.isEmpty());
    Assert.assertTrue("Model contains handlers not in the configuration: " + missingModelHandlers, missingModelHandlers.isEmpty());

    // Compare property values for the handlers
    compareHandlers(logContextConfig, handlerNames, currentModel);

    // Compare logger values
    compareLoggers(logContextConfig, currentModel);

}
 
Example #12
Source File: LoggingConfigurationFileReloader.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private LoggingConfigurationUpdater getOrCreateUpdater() {
   final LogContext logContext = LogContext.getLogContext();
   final org.jboss.logmanager.Logger rootLogger = logContext.getLogger("");
   LoggingConfigurationUpdater updater = rootLogger.getAttachment(KEY);
   if (updater == null) {
      final LogContextConfiguration logContextConfiguration = getOrCreateConfiguration(rootLogger);
      if (logContextConfiguration == null) {
         return null;
      }
      updater = new LoggingConfigurationUpdater(logContextConfiguration);
      final LoggingConfigurationUpdater appearing = rootLogger.attachIfAbsent(KEY, updater);
      if (appearing != null) {
         updater = appearing;
      }
   }
   return updater;
}
 
Example #13
Source File: LoggingDeploymentResources.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #14
Source File: LoggingConfigurator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #15
Source File: PatternFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(name);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.formatterNotFound(name));
    }
    logContextConfiguration.removeFormatterConfiguration(name);
}
 
Example #16
Source File: HandlerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public final void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.handlerConfigurationNotFound(name));
    }
    final AttributeDefinition[] attributes = getAttributes();
    if (attributes != null) {
        boolean restartRequired = false;
        boolean reloadRequired = false;
        for (AttributeDefinition attribute : attributes) {
            // Only update if the attribute is on the operation
            if (operation.has(attribute.getName())) {
                handleProperty(attribute, context, model, logContextConfiguration, configuration);
                restartRequired = restartRequired || Logging.requiresRestart(attribute.getFlags());
                reloadRequired = reloadRequired || Logging.requiresReload(attribute.getFlags());
            }
        }
        if (restartRequired) {
            context.restartRequired();
        } else if (reloadRequired) {
            context.reloadRequired();
        }
    }

    // It's important that properties are written in the correct order, reorder the properties if
    // needed before the commit.
    addOrderPropertiesStep(context, propertySorter, configuration);
}
 
Example #17
Source File: PatternFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) {
    final FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(addressName);
    for (PropertyAttributeDefinition attribute : ATTRIBUTES) {
        if (attribute.getName().equals(attributeName)) {
            configuration.setPropertyValueString(attribute.getPropertyName(), value.asString());
            break;
        }
    }
    return false;
}
 
Example #18
Source File: HandlerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.handlerConfigurationNotFound(name));
    }
    // Uses the operation to get the single handler name being added
    configuration.removeHandlerName(HANDLER_NAME.resolveModelAttribute(context, operation).asString());
}
 
Example #19
Source File: StructuredFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(name);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.formatterNotFound(name));
    }
    logContextConfiguration.removeFormatterConfiguration(name);
}
 
Example #20
Source File: SocketHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName,
                              final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {

    // First get the handler configuration.
    final HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(addressName);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.handlerConfigurationNotFound(addressName));
    }
    // Handle writing the attribute
    if (LEVEL.getName().equals(attributeName)) {
        configuration.setLevel(value.asString());
    } else if (NAMED_FORMATTER.getName().equals(attributeName)) {
        if (value.isDefined()) {
            configuration.setFormatterName(value.asString());
        } else {
            configuration.setFormatterName(null);
        }
    } else if (FILTER_SPEC.getName().equals(attributeName)) {
        if (value.isDefined()) {
            configuration.setFilter(value.asString());
        } else {
            configuration.setFilter(null);
        }
    }
    return Logging.requiresReload(getAttributeDefinition(attributeName).getFlags());

}
 
Example #21
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public final void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String loggerName = getLogManagerLoggerName(context.getCurrentAddressValue());
    LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.loggerConfigurationNotFound(loggerName));
    }
    performRuntime(context, operation, configuration, loggerName, model);
}
 
Example #22
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final String loggerName = getLogManagerLoggerName(name);
    LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
    if (configuration == null) {
        LoggingLogger.ROOT_LOGGER.tracef("Adding logger '%s' at '%s'", name, context.getCurrentAddress());
        configuration = logContextConfiguration.addLoggerConfiguration(loggerName);
    }

    for (AttributeDefinition attribute : attributes) {
        handleProperty(attribute, context, model, configuration);
    }
}
 
Example #23
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    // Disable the logger before removing it
    final String loggerName = getLogManagerLoggerName(context.getCurrentAddressValue());
    final LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.loggerNotFound(loggerName));
    }
    logContextConfiguration.removeLoggerConfiguration(loggerName);
}
 
Example #24
Source File: LoggingOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    final ConfigurationPersistence configurationPersistence = getOrCreateConfigurationPersistence(context);
    final LogContextConfiguration logContextConfiguration = configurationPersistence.getLogContextConfiguration();

    performRuntime(context, operation, model, logContextConfiguration);
    addCommitStep(context, configurationPersistence);
    final OperationStepHandler afterCommit = afterCommit(logContextConfiguration, model);
    if (afterCommit != null) {
        context.addStep(afterCommit, Stage.RUNTIME);
    }
}
 
Example #25
Source File: LoggingOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    final ConfigurationPersistence configurationPersistence = getOrCreateConfigurationPersistence(context);
    final LogContextConfiguration logContextConfiguration = configurationPersistence.getLogContextConfiguration();

    performRuntime(context, operation, model, logContextConfiguration);
    addCommitStep(context, configurationPersistence);
}
 
Example #26
Source File: LoggingOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected final boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<ConfigurationPersistence> handbackHolder) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final ConfigurationPersistence configurationPersistence = getOrCreateConfigurationPersistence(context);
    final LogContextConfiguration logContextConfiguration = configurationPersistence.getLogContextConfiguration();
    handbackHolder.setHandback(configurationPersistence);
    final boolean restartRequired = applyUpdate(context, attributeName, name, resolvedValue, logContextConfiguration);
    addCommitStep(context, configurationPersistence);
    final OperationStepHandler afterCommit = afterCommit(logContextConfiguration, attributeName, resolvedValue, currentValue);
    if (afterCommit != null && !restartRequired) {
        context.addStep(afterCommit, Stage.RUNTIME);
    }
    return restartRequired;
}
 
Example #27
Source File: FilterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final FilterConfiguration configuration = logContextConfiguration.getFilterConfiguration(name);
    if (configuration == null) {
        throw LoggingLogger.ROOT_LOGGER.filterNotFound(name);
    }
    logContextConfiguration.removeFilterConfiguration(name);
}
 
Example #28
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("ChainOfInstanceofChecks")
private LogContextConfiguration getLogContextConfiguration(final LogContext logContext) {
    final Configurator configurator = logContext.getAttachment(CommonAttributes.ROOT_LOGGER_NAME, Configurator.ATTACHMENT_KEY);
    if (configurator instanceof LogContextConfiguration) {
        return (LogContextConfiguration) configurator;
    }
    if (configurator instanceof PropertyConfigurator) {
        return ((PropertyConfigurator) configurator).getLogContextConfiguration();
    }
    return null;
}
 
Example #29
Source File: EmbeddedLogContext.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Attempts to clear the global log context used for embedded servers.
 */
static synchronized void clearLogContext() {
    final LogContext embeddedLogContext = Holder.LOG_CONTEXT;
    // Remove the configurator and clear the log context
    final Configurator configurator = embeddedLogContext.getLogger("").detach(Configurator.ATTACHMENT_KEY);
    // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
    if (configurator instanceof PropertyConfigurator) {
        final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
        clearLogContext(logContextConfiguration);
    } else if (configurator instanceof LogContextConfiguration) {
        clearLogContext((LogContextConfiguration) configurator);
    } else {
        // Remove all the handlers and close them as well as reset the loggers
        final List<String> loggerNames = Collections.list(embeddedLogContext.getLoggerNames());
        for (String name : loggerNames) {
            final Logger logger = embeddedLogContext.getLoggerIfExists(name);
            if (logger != null) {
                final Handler[] handlers = logger.clearHandlers();
                if (handlers != null) {
                    for (Handler handler : handlers) {
                        handler.close();
                    }
                }
                logger.setFilter(null);
                logger.setUseParentFilters(false);
                logger.setUseParentHandlers(true);
                logger.setLevel(Level.INFO);
            }
        }
    }
}
 
Example #30
Source File: EmbeddedLogContext.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void clearLogContext(final LogContextConfiguration logContextConfiguration) {
    try {
        // Remove all the handlers
        for (String s5 : logContextConfiguration.getHandlerNames()) {
            logContextConfiguration.removeHandlerConfiguration(s5);
        }
        // Remove all the formatters
        for (String s4 : logContextConfiguration.getFormatterNames()) {
            logContextConfiguration.removeFormatterConfiguration(s4);
        }
        // Remove all the error managers
        for (String s3 : logContextConfiguration.getErrorManagerNames()) {
            logContextConfiguration.removeErrorManagerConfiguration(s3);
        }
        // Remove all the POJO's
        for (String s2 : logContextConfiguration.getPojoNames()) {
            logContextConfiguration.removePojoConfiguration(s2);
        }
        // Remove all the loggers
        for (String s1 : logContextConfiguration.getLoggerNames()) {
            logContextConfiguration.removeLoggerConfiguration(s1);
        }
        // Remove all the filters
        for (String s : logContextConfiguration.getFilterNames()) {
            logContextConfiguration.removeFilterConfiguration(s);
        }
        logContextConfiguration.commit();
    } finally {
        logContextConfiguration.forget();
    }
}