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