|
|
@@ -58,6 +58,7 @@ |
|
|
import org.jboss.as.logging.Filters; |
|
|
import org.jboss.as.logging.Logging; |
|
|
import org.jboss.as.logging.LoggingOperations; |
|
|
import org.jboss.as.logging.formatters.PatternFormatterResourceDefinition; |
|
|
import org.jboss.as.logging.loggers.RootLoggerResourceDefinition; |
|
|
import org.jboss.as.logging.logging.LoggingLogger; |
|
|
import org.jboss.as.logging.logmanager.Log4jAppenderHandler; |
|
|
@@ -621,39 +622,40 @@ private static void handleProperty(final AttributeDefinition attribute, final Op |
|
|
configuration.setEncoding(resolvedValue); |
|
|
} else if (attribute.getName().equals(FORMATTER.getName())) { |
|
|
// The handler name will be used for the name of a formatter for the formatter attribute |
|
|
final String handlerName = configuration.getName(); |
|
|
final String defaultFormatterName = configuration.getName() + PatternFormatterResourceDefinition.DEFAULT_FORMATTER_SUFFIX; |
|
|
// Get the current model and check for a defined named-formatter attribute |
|
|
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); |
|
|
final ModelNode m = resource.getModel(); |
|
|
if (m.hasDefined(NAMED_FORMATTER.getName())) { |
|
|
// If a named-formatter exists in the model and a formatter already exists with the name of the handler |
|
|
// remove the formatter |
|
|
if (logContextConfiguration.getFormatterNames().contains(handlerName)) { |
|
|
logContextConfiguration.removeFormatterConfiguration(handlerName); |
|
|
if (logContextConfiguration.getFormatterNames().contains(defaultFormatterName)) { |
|
|
logContextConfiguration.removeFormatterConfiguration(defaultFormatterName); |
|
|
} |
|
|
} else { |
|
|
// Create a formatter based on the handlers name |
|
|
final FormatterConfiguration fmtConfig; |
|
|
if (logContextConfiguration.getFormatterNames().contains(handlerName)) { |
|
|
fmtConfig = logContextConfiguration.getFormatterConfiguration(handlerName); |
|
|
if (logContextConfiguration.getFormatterNames().contains(defaultFormatterName)) { |
|
|
fmtConfig = logContextConfiguration.getFormatterConfiguration(defaultFormatterName); |
|
|
} else { |
|
|
fmtConfig = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), handlerName, PATTERN.getPropertyName()); |
|
|
fmtConfig = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), defaultFormatterName, PATTERN.getPropertyName()); |
|
|
} |
|
|
final String resolvedValue = (resolveValue ? FORMATTER.resolvePropertyValue(context, model) : model.asString()); |
|
|
fmtConfig.setPropertyValueString(PATTERN.getPropertyName(), resolvedValue); |
|
|
configuration.setFormatterName(handlerName); |
|
|
configuration.setFormatterName(defaultFormatterName); |
|
|
} |
|
|
} else if (attribute.getName().equals(NAMED_FORMATTER.getName())) { |
|
|
// The name of the handler will be used for a "formatter" if the named-formatter is not defined |
|
|
final String handlerName = configuration.getName(); |
|
|
final String defaultFormatterName = handlerName + PatternFormatterResourceDefinition.DEFAULT_FORMATTER_SUFFIX; |
|
|
final ModelNode valueNode = (resolveValue ? NAMED_FORMATTER.resolveModelAttribute(context, model) : model); |
|
|
// Set the formatter if the value is defined |
|
|
if (valueNode.isDefined()) { |
|
|
final String resolvedValue = valueNode.asString(); |
|
|
configuration.setFormatterName(resolvedValue); |
|
|
// If the formatter was previously defined by the formatter attribute, remove the formatter |
|
|
if (logContextConfiguration.getFormatterNames().contains(handlerName)) { |
|
|
logContextConfiguration.removeFormatterConfiguration(handlerName); |
|
|
if (logContextConfiguration.getFormatterNames().contains(defaultFormatterName)) { |
|
|
logContextConfiguration.removeFormatterConfiguration(defaultFormatterName); |
|
|
} |
|
|
} else if (configuration.getClassName().equals(SyslogHandler.class.getName())) { |
|
|
// The value shouldn't be defined so we want to remove the current formatter, however a null formatter |
|
|
@@ -668,15 +670,15 @@ private static void handleProperty(final AttributeDefinition attribute, final Op |
|
|
} else { |
|
|
// If the named-formatter was undefined we need to create a formatter based on the formatter attribute |
|
|
final FormatterConfiguration fmtConfig; |
|
|
if (logContextConfiguration.getFormatterNames().contains(handlerName)) { |
|
|
fmtConfig = logContextConfiguration.getFormatterConfiguration(handlerName); |
|
|
if (logContextConfiguration.getFormatterNames().contains(defaultFormatterName)) { |
|
|
fmtConfig = logContextConfiguration.getFormatterConfiguration(defaultFormatterName); |
|
|
} else { |
|
|
fmtConfig = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), handlerName, PATTERN.getPropertyName()); |
|
|
fmtConfig = logContextConfiguration.addFormatterConfiguration(null, PatternFormatter.class.getName(), defaultFormatterName, PATTERN.getPropertyName()); |
|
|
} |
|
|
// Get the current model and set the value of the formatter based on the formatter attribute |
|
|
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); |
|
|
fmtConfig.setPropertyValueString(PATTERN.getPropertyName(), FORMATTER.resolvePropertyValue(context, resource.getModel())); |
|
|
configuration.setFormatterName(handlerName); |
|
|
configuration.setFormatterName(defaultFormatterName); |
|
|
} |
|
|
} else if (attribute.getName().equals(FILTER_SPEC.getName())) { |
|
|
final ModelNode valueNode = (resolveValue ? FILTER_SPEC.resolveModelAttribute(context, model) : model); |
|
|
|