Search in sources :

Example 1 with LogContextConfiguration

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));
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration)

Example 2 with LogContextConfiguration

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();
    }
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) Configurator(org.jboss.logmanager.Configurator) LogContext(org.jboss.logmanager.LogContext) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Example 3 with LogContextConfiguration

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());
    }
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) PathElement(org.jboss.as.controller.PathElement)

Example 4 with LogContextConfiguration

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"));
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) LoggerConfiguration(org.jboss.logmanager.config.LoggerConfiguration) HandlerConfiguration(org.jboss.logmanager.config.HandlerConfiguration) CompositeOperationBuilder(org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 5 with LogContextConfiguration

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;
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) Configurator(org.jboss.logmanager.Configurator) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Aggregations

LogContextConfiguration (org.jboss.logmanager.config.LogContextConfiguration)14 Configurator (org.jboss.logmanager.Configurator)4 LogContext (org.jboss.logmanager.LogContext)4 PropertyConfigurator (org.jboss.logmanager.PropertyConfigurator)4 ModelNode (org.jboss.dmr.ModelNode)3 ArrayList (java.util.ArrayList)2 HandlerConfiguration (org.jboss.logmanager.config.HandlerConfiguration)2 Test (org.junit.Test)2 List (java.util.List)1 Handler (java.util.logging.Handler)1 PathElement (org.jboss.as.controller.PathElement)1 Operation (org.jboss.as.controller.client.Operation)1 CompositeOperationBuilder (org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder)1 Operations.createAddOperation (org.jboss.as.controller.client.helpers.Operations.createAddOperation)1 Operations.createRemoveOperation (org.jboss.as.controller.client.helpers.Operations.createRemoveOperation)1 Resource (org.jboss.as.controller.registry.Resource)1 LoggingConfigDeploymentProcessor (org.jboss.as.logging.deployments.LoggingConfigDeploymentProcessor)1 LoggingDependencyDeploymentProcessor (org.jboss.as.logging.deployments.LoggingDependencyDeploymentProcessor)1 LoggingDeploymentResourceProcessor (org.jboss.as.logging.deployments.LoggingDeploymentResourceProcessor)1 LoggingProfileDeploymentProcessor (org.jboss.as.logging.deployments.LoggingProfileDeploymentProcessor)1