Search in sources :

Example 6 with LogContextConfiguration

use of org.jboss.logmanager.config.LogContextConfiguration in project activemq-artemis by apache.

the class LoggingConfigurationFileReloader method getOrCreateUpdater.

private LoggingConfigurationUpdater getOrCreateUpdater() {
    final LogContext logContext = LogContext.getLogContext();
    final org.jboss.logmanager.Logger rootLogger = logContext.getLogger("");
    LoggingConfigurationUpdater updater = rootLogger.getAttachment(KEY);
    if (updater == null) {
        final LogContextConfiguration logContextConfiguration = getOrCreateConfiguration(rootLogger);
        if (logContextConfiguration == null) {
            return null;
        }
        updater = new LoggingConfigurationUpdater(logContextConfiguration);
        final LoggingConfigurationUpdater appearing = rootLogger.attachIfAbsent(KEY, updater);
        if (appearing != null) {
            updater = appearing;
        }
    }
    return updater;
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) LogContext(org.jboss.logmanager.LogContext)

Example 7 with LogContextConfiguration

use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-swarm by wildfly-swarm.

the class LoggingConfigurator method configure.

@Override
public void configure(InputStream inputStream) throws IOException {
    this.propertyConfigurator.configure(inputStream);
    LogContextConfiguration config = this.propertyConfigurator.getLogContextConfiguration();
    config.getHandlerConfiguration("CONSOLE").setLevel("ALL");
    LevelNode root = InitialLoggerManager.INSTANCE.getRoot();
    apply(root, config);
    config.commit();
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) LevelNode(org.wildfly.swarm.bootstrap.logging.LevelNode)

Example 8 with LogContextConfiguration

use of org.jboss.logmanager.config.LogContextConfiguration in project activemq-artemis by apache.

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)

Example 9 with LogContextConfiguration

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

the class HandlerOperationsTestCase method testCompositeOperations.

/**
 * Tests a composite operation of undefining a {@code formatter} attribute and defining a {@code named-formatter}
 * attribute in a composite operation. These two specific attributes have strange behavior. If the
 * {@code named-formatter} is defined it removes the formatter, named the same as the handler, which was created
 * as part of the {@code undefine-attribute} operation of the {@code formatter} attribute.
 */
@Test
public void testCompositeOperations() {
    final ModelNode address = createFileHandlerAddress("FILE").toModelNode();
    final String filename = "test-file.log";
    final String defaultFormatterName = PatternFormatterResourceDefinition.getDefaultFomatterName("FILE");
    // Add the handler
    ModelNode addOp = OperationBuilder.createAddOperation(address).addAttribute(CommonAttributes.FILE, createFileValue("jboss.server.log.dir", filename)).build();
    executeOperation(kernelServices, addOp);
    final ModelNode patternFormatterAddress = createPatternFormatterAddress("PATTERN").toModelNode();
    addOp = SubsystemOperations.createAddOperation(patternFormatterAddress);
    addOp.get(PatternFormatterResourceDefinition.PATTERN.getName()).set("%d{HH:mm:ss,SSS} %-5p [%c] %s%e%n");
    executeOperation(kernelServices, addOp);
    // Create a composite operation to undefine
    final Operation op = CompositeOperationBuilder.create().addStep(SubsystemOperations.createUndefineAttributeOperation(address, "formatter")).addStep(SubsystemOperations.createWriteAttributeOperation(address, "named-formatter", "PATTERN")).build();
    executeOperation(kernelServices, op.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);
    assertFalse("Expected the default formatter named " + defaultFormatterName + " to be removed for the handler FILE", configuration.getFormatterNames().contains(defaultFormatterName));
    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());
    // Undefine the named-formatter to ensure a formatter is created
    executeOperation(kernelServices, SubsystemOperations.createUndefineAttributeOperation(address, "named-formatter"));
    assertTrue("Expected the default formatter named " + defaultFormatterName + " to be added", configuration.getFormatterNames().contains(defaultFormatterName));
    assertEquals("Expected the handler named FILE to use the FILE formatter", defaultFormatterName, handlerConfiguration.getFormatterName());
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) HandlerConfiguration(org.jboss.logmanager.config.HandlerConfiguration) Operation(org.jboss.as.controller.client.Operation) Operations.createAddOperation(org.jboss.as.controller.client.helpers.Operations.createAddOperation) Operations.createRemoveOperation(org.jboss.as.controller.client.helpers.Operations.createRemoveOperation) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 10 with LogContextConfiguration

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

the class AbstractLoggingSubsystemTest method compare.

void compare(final ModelNode currentModel, final ConfigurationPersistence config) throws OperationFailedException {
    final LogContextConfiguration logContextConfig = config.getLogContextConfiguration();
    final List<String> handlerNames = logContextConfig.getHandlerNames();
    final List<String> modelHandlerNames = getHandlerNames(currentModel);
    final List<String> missingConfigHandlers = new ArrayList<>(handlerNames);
    missingConfigHandlers.removeAll(modelHandlerNames);
    final List<String> missingModelHandlers = new ArrayList<>(modelHandlerNames);
    missingModelHandlers.removeAll(handlerNames);
    Assert.assertTrue("Configuration contains handlers not in the model: " + missingConfigHandlers, missingConfigHandlers.isEmpty());
    Assert.assertTrue("Model contains handlers not in the configuration: " + missingModelHandlers, missingModelHandlers.isEmpty());
    // Compare property values for the handlers
    compareHandlers(logContextConfig, handlerNames, currentModel);
    // Compare logger values
    compareLoggers(logContextConfig, currentModel);
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) ArrayList(java.util.ArrayList)

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