Java Code Examples for org.jboss.logmanager.config.LogContextConfiguration#removeFormatterConfiguration()

The following examples show how to use org.jboss.logmanager.config.LogContextConfiguration#removeFormatterConfiguration() . 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: 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 2
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 3
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 4
Source File: CustomFormatterResourceDefinition.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 5
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();
    }
}
 
Example 6
Source File: StructuredFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings({"OverlyStrongTypeCast", "StatementWithEmptyBody"})
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    String keyOverrides = null;
    if (model.hasDefined(KEY_OVERRIDES.getName())) {
        keyOverrides = modelValueToMetaData(KEY_OVERRIDES.resolveModelAttribute(context, model));
    }

    final String name = context.getCurrentAddressValue();
    if (name.endsWith(PatternFormatterResourceDefinition.DEFAULT_FORMATTER_SUFFIX)) {
        throw LoggingLogger.ROOT_LOGGER.illegalFormatterName();
    }
    FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(name);
    final String className = type.getName();

    if (configuration == null) {
        LoggingLogger.ROOT_LOGGER.tracef("Adding formatter '%s' at '%s'", name, context.getCurrentAddress());
        if (keyOverrides == null) {
            configuration = logContextConfiguration.addFormatterConfiguration(null, className, name);
        } else {
            configuration = logContextConfiguration.addFormatterConfiguration(null, className, name, "keyOverrides");
            configuration.setPropertyValueString("keyOverrides", keyOverrides);
        }
    } else if (isSamePropertyValue(configuration, "keyOverrides", keyOverrides)) {
        LoggingLogger.ROOT_LOGGER.tracef("Removing then adding formatter '%s' at '%s'", name, context.getCurrentAddress());
        logContextConfiguration.removeFormatterConfiguration(name);
        configuration = logContextConfiguration.addFormatterConfiguration(null, className, name, "keyOverrides");
        configuration.setPropertyValueString("keyOverrides", keyOverrides);
    }

    // Process the attributes
    for (AttributeDefinition attribute : attributes) {
        if (attribute == META_DATA) {
            final String metaData = modelValueToMetaData(META_DATA.resolveModelAttribute(context, model));
            if (metaData != null) {
                if (isSamePropertyValue(configuration, "metaData", metaData)) {
                    configuration.setPropertyValueString("metaData", metaData);
                }
            } else {
                configuration.removeProperty("metaData");
            }
        } else if (attribute == KEY_OVERRIDES) {
            // Ignore the key-overrides as it was already taken care of
        } else {
            if (attribute instanceof PropertyAttributeDefinition) {
                ((PropertyAttributeDefinition) attribute).setPropertyValue(context, model, configuration);
            } else {
                final ModelNode value = attribute.resolveModelAttribute(context, model);
                if (value.isDefined()) {
                    if (isSamePropertyValue(configuration, attribute.getName(), value.asString())) {
                        configuration.setPropertyValueString(attribute.getName(), value.asString());
                    }
                } else {
                    configuration.removeProperty(attribute.getName());
                }
            }
        }
    }
}