Search in sources :

Example 6 with LogContext

use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.

the class LoggingProfileDeploymentProcessor method processDeployment.

@Override
protected void processDeployment(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit, final ResourceRoot root) throws DeploymentUnitProcessingException {
    LoggingConfigurationService loggingConfigurationService = null;
    final List<DeploymentUnit> subDeployments = getSubDeployments(deploymentUnit);
    final String loggingProfile = findLoggingProfile(root);
    if (loggingProfile != null) {
        // Get the profile logging context
        final LoggingProfileContextSelector loggingProfileContext = LoggingProfileContextSelector.getInstance();
        if (loggingProfileContext.exists(loggingProfile)) {
            // Get the module
            final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
            final LogContext logContext = loggingProfileContext.get(loggingProfile);
            LoggingLogger.ROOT_LOGGER.tracef("Registering log context '%s' on '%s' for profile '%s'", logContext, root, loggingProfile);
            registerLogContext(deploymentUnit, module, logContext);
            loggingConfigurationService = new LoggingConfigurationService(ConfigurationPersistence.getConfigurationPersistence(logContext), "profile-" + loggingProfile);
            // Process sub-deployments
            for (DeploymentUnit subDeployment : subDeployments) {
                // Set the result to true if a logging profile was found
                if (subDeployment.hasAttachment(Attachments.DEPLOYMENT_ROOT)) {
                    processDeployment(phaseContext, subDeployment, subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT));
                }
                if (!hasRegisteredLogContext(subDeployment)) {
                    final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE);
                    LoggingLogger.ROOT_LOGGER.tracef("Registering log context '%s' on '%s' for profile '%s'", logContext, subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT), loggingProfile);
                    registerLogContext(subDeployment, subDeploymentModule, logContext);
                }
                // Add the parents service to the sub-deployment if the sub-deployment did not define it's own log context
                if (!subDeployment.hasAttachment(LoggingDeploymentResourceProcessor.LOGGING_CONFIGURATION_SERVICE_KEY)) {
                    subDeployment.putAttachment(LoggingDeploymentResourceProcessor.LOGGING_CONFIGURATION_SERVICE_KEY, loggingConfigurationService);
                }
            }
        } else {
            LoggingLogger.ROOT_LOGGER.loggingProfileNotFound(loggingProfile, root);
        }
    } else {
        // No logging profile found, but the sub-deployments should be checked for logging profiles
        for (DeploymentUnit subDeployment : subDeployments) {
            // A sub-deployment must have a root resource to process
            if (subDeployment.hasAttachment(Attachments.DEPLOYMENT_ROOT)) {
                processDeployment(phaseContext, subDeployment, subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT));
            }
        }
    }
    // Add the service to the deployment unit
    if (loggingConfigurationService != null) {
        deploymentUnit.putAttachment(LoggingDeploymentResourceProcessor.LOGGING_CONFIGURATION_SERVICE_KEY, loggingConfigurationService);
    }
}
Also used : LoggingProfileContextSelector(org.jboss.as.logging.LoggingProfileContextSelector) LogContext(org.jboss.logmanager.LogContext) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 7 with LogContext

use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.

the class LogContextStdioContextSelector method getStdioContext.

@Override
public StdioContext getStdioContext() {
    final LogContext logContext = LogContext.getLogContext();
    final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
    StdioContext stdioContext = root.getAttachment(STDIO_CONTEXT_ATTACHMENT_KEY);
    if (stdioContext == null) {
        // Create the StdioContext
        stdioContext = createContext(logContext);
        final StdioContext appearing = attachIfAbsent(root, stdioContext);
        if (appearing != null) {
            stdioContext = appearing;
        }
    }
    return stdioContext;
}
Also used : LogContext(org.jboss.logmanager.LogContext) StdioContext(org.jboss.stdio.StdioContext) Logger(org.jboss.logmanager.Logger)

Example 8 with LogContext

use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method rollbackWriteAttribute.

public void rollbackWriteAttribute(final String profileName) throws Exception {
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    // Add a handler to be removed
    final PathAddress consoleHandler = createConsoleHandlerAddress(profileName, "CONSOLE");
    // Create a new handler
    ModelNode op = SubsystemOperations.createWriteAttributeOperation(consoleHandler.toModelNode(), ConsoleHandlerResourceDefinition.TARGET, "System.err");
    ModelNode result = kernelServices.executeOperation(op);
    Assert.assertFalse("The write operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    final LogContext logContext = (profileName == null ? LogContext.getLogContext() : LoggingProfileContextSelector.getInstance().get(profileName));
    ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
    // Fail on a logger write attribute
    final PathAddress rootLoggerAddress = createRootLoggerAddress(profileName);
    op = SubsystemOperations.createWriteAttributeOperation(rootLoggerAddress.toModelNode(), CommonAttributes.LEVEL, "TRACE");
    result = kernelServices.executeOperation(op);
    Assert.assertFalse("The write operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
}
Also used : ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) LogContext(org.jboss.logmanager.LogContext) ModelNode(org.jboss.dmr.ModelNode)

Example 9 with LogContext

use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method rollbackAdd.

public void rollbackAdd(final String profileName) throws Exception {
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    // Add a handler to be removed
    final PathAddress consoleHandler = createConsoleHandlerAddress(profileName, "CONSOLE2");
    // Create a new handler
    ModelNode op = SubsystemOperations.createAddOperation(consoleHandler.toModelNode());
    op.get(CommonAttributes.LEVEL.getName()).set("INFO");
    op.get(AbstractHandlerDefinition.FORMATTER.getName()).set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) CONSOLE2: %s%e%n");
    ModelNode result = kernelServices.executeOperation(op);
    Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    final LogContext logContext = (profileName == null ? LogContext.getLogContext() : LoggingProfileContextSelector.getInstance().get(profileName));
    ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
    // Fail on a logger write attribute
    final PathAddress loggerAddress = createLoggerAddress(profileName, "org.jboss.as.logging.test");
    op = SubsystemOperations.createAddOperation(loggerAddress.toModelNode());
    result = kernelServices.executeOperation(op);
    Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
}
Also used : ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) LogContext(org.jboss.logmanager.LogContext) ModelNode(org.jboss.dmr.ModelNode)

Example 10 with LogContext

use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.

the class LoggingSubsystemTestCase method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    final KernelServices kernelServices = boot();
    final ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(currentModel, ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext()));
    // Compare properties written out to current model
    final String dir = resolveRelativePath(kernelServices, "jboss.server.config.dir");
    Assert.assertNotNull("jboss.server.config.dir could not be resolved", dir);
    final LogContext logContext = LogContext.create();
    final ConfigurationPersistence config = ConfigurationPersistence.getOrCreateConfigurationPersistence(logContext);
    try (final FileInputStream in = new FileInputStream(new File(dir, "logging.properties"))) {
        config.configure(in);
        compare(currentModel, config);
    }
    kernelServices.shutdown();
}
Also used : ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) KernelServices(org.jboss.as.subsystem.test.KernelServices) LogContext(org.jboss.logmanager.LogContext) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

LogContext (org.jboss.logmanager.LogContext)33 ModelNode (org.jboss.dmr.ModelNode)7 PathAddress (org.jboss.as.controller.PathAddress)6 ConfigurationPersistence (org.jboss.as.logging.logmanager.ConfigurationPersistence)6 Logger (org.jboss.logmanager.Logger)6 ArrayList (java.util.ArrayList)5 Level (java.util.logging.Level)5 PropertyConfigurator (org.jboss.logmanager.PropertyConfigurator)5 File (java.io.File)4 InputStream (java.io.InputStream)4 LogContextConfiguration (org.jboss.logmanager.config.LogContextConfiguration)4 StdioContext (org.jboss.stdio.StdioContext)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Properties (java.util.Properties)3 Handler (java.util.logging.Handler)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Configurator (org.jboss.logmanager.Configurator)3