Java Code Examples for org.jboss.logmanager.config.LogContextConfiguration#getLoggerConfiguration()

The following examples show how to use org.jboss.logmanager.config.LogContextConfiguration#getLoggerConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String loggerName = getLogManagerLoggerName(addressName);
    if (logContextConfiguration.getLoggerNames().contains(loggerName)) {
        final LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
        if (LEVEL.getName().equals(attributeName)) {
            handleProperty(LEVEL, context, value, configuration, false);
        } else if (FILTER.getName().equals(attributeName)) {
            // Filter should be replaced by the filter-spec in the super class
            handleProperty(FILTER_SPEC, context, value, configuration, false);
        } else if (FILTER_SPEC.getName().equals(attributeName)) {
            handleProperty(FILTER_SPEC, context, value, configuration, false);
        } else if (HANDLERS.getName().equals(attributeName)) {
            handleProperty(HANDLERS, context, value, configuration, false);
        } else if (USE_PARENT_HANDLERS.getName().equals(attributeName)) {
            handleProperty(USE_PARENT_HANDLERS, context, value, configuration, false);
        }
    }
    return false;
}
 
Example 2
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public final void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String loggerName = getLogManagerLoggerName(context.getCurrentAddressValue());
    LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.loggerConfigurationNotFound(loggerName));
    }
    performRuntime(context, operation, configuration, loggerName, model);
}
 
Example 3
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final String loggerName = getLogManagerLoggerName(name);
    LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
    if (configuration == null) {
        LoggingLogger.ROOT_LOGGER.tracef("Adding logger '%s' at '%s'", name, context.getCurrentAddress());
        configuration = logContextConfiguration.addLoggerConfiguration(loggerName);
    }

    for (AttributeDefinition attribute : attributes) {
        handleProperty(attribute, context, model, configuration);
    }
}
 
Example 4
Source File: LoggerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    // Disable the logger before removing it
    final String loggerName = getLogManagerLoggerName(context.getCurrentAddressValue());
    final LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(loggerName);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.loggerNotFound(loggerName));
    }
    logContextConfiguration.removeLoggerConfiguration(loggerName);
}
 
Example 5
Source File: LoggerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void updateModel(final LogContextConfiguration logContextConfiguration, final String name, final ModelNode model) {
    final LoggerConfiguration configuration = logContextConfiguration.getLoggerConfiguration(RootLoggerResourceDefinition.RESOURCE_NAME.equals(name) ? "" : name);
    updateModel(configuration, model);

}
 
Example 6
Source File: HandlerOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@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"));
}