use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class HandlerOperationsTestCase method verifyRemoved.
@Override
protected void verifyRemoved(KernelServices kernelServices, ModelNode address) {
super.verifyRemoved(kernelServices, address);
final LogContextConfiguration configuration = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
final String name = address.get(address.asInt() - 1).asProperty().getValue().asString();
final String defaultFormatterName = PatternFormatterResourceDefinition.getDefaultFomatterName(name);
assertFalse("Expected the default formatter named " + defaultFormatterName + " to be removed for the handler " + name, configuration.getFormatterNames().contains(defaultFormatterName));
}
use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class LoggingDeploymentResourceProcessor method deploy.
@Override
public final void deploy(final DeploymentPhaseContext phaseContext) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.hasAttachment(Attachments.MODULE)) {
LoggingConfigurationService loggingConfigurationService;
if (deploymentUnit.hasAttachment(LOGGING_CONFIGURATION_SERVICE_KEY)) {
loggingConfigurationService = deploymentUnit.getAttachment(LOGGING_CONFIGURATION_SERVICE_KEY);
// Remove the attachment as it should no longer be needed
deploymentUnit.removeAttachment(LOGGING_CONFIGURATION_SERVICE_KEY);
} else {
// Get the module
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
// Set the deployments class loader to ensure we get the correct log context
final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
LogContextConfiguration logContextConfiguration = null;
final LogContext logContext = LogContext.getLogContext();
final Configurator configurator = logContext.getAttachment(CommonAttributes.ROOT_LOGGER_NAME, Configurator.ATTACHMENT_KEY);
if (configurator instanceof LogContextConfiguration) {
logContextConfiguration = (LogContextConfiguration) configurator;
} else if (configurator instanceof PropertyConfigurator) {
logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
}
loggingConfigurationService = new LoggingConfigurationService(logContextConfiguration, "default");
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(current);
}
}
final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
// Register the resources
LoggingDeploymentResources.registerDeploymentResource(deploymentResourceSupport, loggingConfigurationService);
phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append("logging", "configuration"), loggingConfigurationService).install();
}
}
use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class LoggingDeploymentResources method registerDeploymentResource.
/**
* 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());
}
}
use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class HandlerOperationsTestCase method testAddHandlerComposite.
@Test
public void testAddHandlerComposite() {
final ModelNode handlerAddress = createFileHandlerAddress("FILE").toModelNode();
final String filename = "test-file-2.log";
final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
// Add the handler
builder.addStep(OperationBuilder.createAddOperation(handlerAddress).addAttribute(CommonAttributes.FILE, createFileValue("jboss.server.log.dir", filename)).build());
// Create a formatter and add it
final ModelNode patternFormatterAddress = createPatternFormatterAddress("PATTERN").toModelNode();
builder.addStep(OperationBuilder.createAddOperation(patternFormatterAddress).addAttribute(PatternFormatterResourceDefinition.PATTERN, "%d{HH:mm:ss,SSS} %-5p [%c] %s%e%n").build());
// Write the named-formatter
builder.addStep(SubsystemOperations.createWriteAttributeOperation(handlerAddress, "named-formatter", "PATTERN"));
// Create an async-handler
final ModelNode asyncHandlerAddress = createAsyncHandlerAddress(null, "ASYNC").toModelNode();
builder.addStep(OperationBuilder.createAddOperation(asyncHandlerAddress).addAttribute(AsyncHandlerResourceDefinition.QUEUE_LENGTH, 100).build());
// Add the file-handler to the async-handler
ModelNode addHandlerOp = SubsystemOperations.createOperation("add-handler", asyncHandlerAddress);
addHandlerOp.get("name").set("FILE");
builder.addStep(addHandlerOp);
// Create a logger
final ModelNode loggerAddress = createLoggerAddress("org.jboss.as.logging").toModelNode();
builder.addStep(SubsystemOperations.createAddOperation(loggerAddress));
// Use the add-handler operation to add the handler to the logger
addHandlerOp = SubsystemOperations.createOperation("add-handler", loggerAddress);
addHandlerOp.get("name").set("ASYNC");
builder.addStep(addHandlerOp);
executeOperation(kernelServices, builder.build().getOperation());
// Get the log context configuration to validate what has been configured
final LogContextConfiguration configuration = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
assertNotNull("Expected to find the configuration", configuration);
final HandlerConfiguration handlerConfiguration = configuration.getHandlerConfiguration("FILE");
assertNotNull("Expected to find the configuration for the FILE handler", configuration);
assertEquals("Expected the handler named FILE to use the PATTERN formatter", "PATTERN", handlerConfiguration.getFormatterName());
final LoggerConfiguration loggerConfiguration = configuration.getLoggerConfiguration("org.jboss.as.logging");
assertNotNull("Expected the logger configuration for org.jboss.as.logging to exist", loggerConfiguration);
assertTrue("Expected the FILE handler to be assigned", loggerConfiguration.getHandlerNames().contains("ASYNC"));
}
use of org.jboss.logmanager.config.LogContextConfiguration in project activemq-artemis by rh-messaging.
the class LoggingConfigurationFileReloader method getOrCreateConfiguration.
private LogContextConfiguration getOrCreateConfiguration(final org.jboss.logmanager.Logger rootLogger) {
Configurator configurator = rootLogger.getAttachment(Configurator.ATTACHMENT_KEY);
if (configurator == null) {
configurator = new PropertyConfigurator(rootLogger.getLogContext());
final Configurator appearing = rootLogger.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
if (appearing != null) {
configurator = appearing;
}
}
if (configurator instanceof PropertyConfigurator) {
return ((PropertyConfigurator) configurator).getLogContextConfiguration();
}
if (configurator instanceof LogContextConfiguration) {
return (LogContextConfiguration) configurator;
}
return null;
}
Aggregations