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);
}
}
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;
}
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);
}
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);
}
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();
}
Aggregations