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

The following examples show how to use org.jboss.logmanager.config.LogContextConfiguration#getFormatterConfiguration() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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());
                }
            }
        }
    }
}
 
Example 9
Source File: StructuredFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 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);
    if (attributeName.equals(META_DATA.getName())) {
        final String metaData = modelValueToMetaData(value);
        if (metaData != null) {
            configuration.setPropertyValueString("metaData", metaData);
        } else {
            configuration.removeProperty("metaData");
        }
    } else if (attributeName.equals(KEY_OVERRIDES.getName())) {
        // Require a restart of the resource
        return true;
    } else {
        for (AttributeDefinition attribute : DEFAULT_ATTRIBUTES) {
            if (attribute.getName().equals(attributeName)) {
                if (attribute instanceof PropertyAttributeDefinition) {
                    final PropertyAttributeDefinition propertyAttribute = (PropertyAttributeDefinition) attribute;
                    if (value.isDefined()) {
                        final ModelNodeResolver<String> resolver = propertyAttribute.resolver();
                        String resolvedValue = value.asString();
                        if (resolver != null) {
                            resolvedValue = resolver.resolveValue(context, value);
                        }
                        configuration.setPropertyValueString(propertyAttribute.getPropertyName(), resolvedValue);
                    } else {
                        configuration.removeProperty(propertyAttribute.getPropertyName());
                    }
                } else {
                    if (value.isDefined()) {
                        configuration.setPropertyValueString(attributeName, value.asString());
                    } else {
                        configuration.removeProperty(attributeName);
                    }
                }
                break;
            }
        }
    }
    return false;
}
 
Example 10
Source File: LoggingDeploymentResources.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected PropertyConfigurable getPropertyConfigurable(final LogContextConfiguration logContextConfiguration, final String name) {
    return logContextConfiguration.getFormatterConfiguration(name);
}
 
Example 11
Source File: LoggingDeploymentResources.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected ObjectConfigurable getObjectConfigurable(final LogContextConfiguration logContextConfiguration, final String name) {
    return logContextConfiguration.getFormatterConfiguration(name);
}