use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class LoggingSubsystemAdd method performRuntime.
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
final boolean addDependencies = LoggingResourceDefinition.ADD_LOGGING_API_DEPENDENCIES.resolveModelAttribute(context, model).asBoolean();
final boolean useLoggingConfig = LoggingResourceDefinition.USE_DEPLOYMENT_LOGGING_CONFIG.resolveModelAttribute(context, model).asBoolean();
context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(final DeploymentProcessorTarget processorTarget) {
if (addDependencies) {
processorTarget.addDeploymentProcessor(LoggingExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_LOGGING, new LoggingDependencyDeploymentProcessor());
}
processorTarget.addDeploymentProcessor(LoggingExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_LOGGING_CONFIG, new LoggingConfigDeploymentProcessor(contextSelector, LoggingResourceDefinition.USE_DEPLOYMENT_LOGGING_CONFIG.getName(), useLoggingConfig));
processorTarget.addDeploymentProcessor(LoggingExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_LOGGING_PROFILE, new LoggingProfileDeploymentProcessor(contextSelector));
processorTarget.addDeploymentProcessor(LoggingExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_LOGGING_DEPLOYMENT_RESOURCES, new LoggingDeploymentResourceProcessor());
}
}, Stage.RUNTIME);
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
final ConfigurationPersistence configurationPersistence = ConfigurationPersistence.getOrCreateConfigurationPersistence();
final LogContextConfiguration logContextConfiguration = configurationPersistence.getLogContextConfiguration();
// root logger
if (!resource.hasChild(RootLoggerResourceDefinition.ROOT_LOGGER_PATH)) {
LoggingLogger.ROOT_LOGGER.tracef("Removing the root logger configuration.");
logContextConfiguration.removeLoggerConfiguration(CommonAttributes.ROOT_LOGGER_NAME);
}
// remove all configured loggers which aren't in the model
if (resource.hasChild(PathElement.pathElement(LoggerResourceDefinition.NAME))) {
final Set<String> loggerNames = resource.getChildrenNames(LoggerResourceDefinition.NAME);
final List<String> configuredLoggerNames = logContextConfiguration.getLoggerNames();
// Always remove the root
configuredLoggerNames.remove(CommonAttributes.ROOT_LOGGER_NAME);
configuredLoggerNames.removeAll(loggerNames);
for (String name : configuredLoggerNames) {
LoggingLogger.ROOT_LOGGER.tracef("Removing logger configuration for '%s'", name);
logContextConfiguration.removeLoggerConfiguration(name);
}
}
// Create a collection of all subsystem handlers
final Collection<String> subsystemHandlers = new ArrayList<>();
subsystemHandlers.addAll(resource.getChildrenNames(AsyncHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(ConsoleHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(CustomHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(FileHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(PeriodicHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(PeriodicSizeRotatingHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(SizeRotatingHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(SocketHandlerResourceDefinition.NAME));
subsystemHandlers.addAll(resource.getChildrenNames(SyslogHandlerResourceDefinition.NAME));
// handlers
final List<String> configuredHandlerNames = logContextConfiguration.getHandlerNames();
configuredHandlerNames.removeAll(subsystemHandlers);
for (String name : configuredHandlerNames) {
LoggingLogger.ROOT_LOGGER.tracef("Removing handler configuration for '%s'", name);
// Clean up any possible POJO references
logContextConfiguration.removePojoConfiguration(name);
// Remove the handler configuration
logContextConfiguration.removeHandlerConfiguration(name);
}
// Remove formatters
final List<String> configuredFormatters = logContextConfiguration.getFormatterNames();
configuredFormatters.removeAll(resource.getChildrenNames(PatternFormatterResourceDefinition.NAME));
configuredFormatters.removeAll(resource.getChildrenNames(CustomFormatterResourceDefinition.NAME));
configuredFormatters.removeAll(resource.getChildrenNames(JsonFormatterResourceDefinition.NAME));
// Formatter names could also be the name of a handler if the formatter attribute is used rather than a named-formatter
configuredFormatters.removeAll(subsystemHandlers);
for (String name : configuredFormatters) {
LoggingLogger.ROOT_LOGGER.tracef("Removing formatter configuration for '%s'", name);
// Remove the formatter configuration
logContextConfiguration.removeFormatterConfiguration(name);
}
LoggingOperations.addCommitStep(context, configurationPersistence);
LoggingLogger.ROOT_LOGGER.trace("Logging subsystem has been added.");
}
use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class LoggingConfigurationReadStepHandler method execute.
@Override
public void execute(final OperationContext context, final ModelNode operation) {
LogContextConfiguration configuration = null;
// Lookup the service
final ServiceController<?> controller = context.getServiceRegistry(false).getService(getServiceName(context));
if (controller != null) {
configuration = (LogContextConfiguration) controller.getValue();
}
// Some deployments may not have a logging configuration associated, e.g. log4j configured deployments
if (configuration != null) {
// Attempt to resolve the resource to ensure it exists before continuing, this can be removed when
// WFCORE-1800 is resolved
context.readResource(PathAddress.EMPTY_ADDRESS, false);
final String name = context.getCurrentAddressValue();
final ModelNode result = context.getResult();
updateModel(configuration, name, result);
}
}
use of org.jboss.logmanager.config.LogContextConfiguration in project wildfly-core by wildfly.
the class EmbeddedLogContext method clearLogContext.
/**
* Attempts to clear the global log context used for embedded servers.
*/
static synchronized void clearLogContext() {
final LogContext embeddedLogContext = Holder.LOG_CONTEXT;
// Remove the configurator and clear the log context
final Configurator configurator = embeddedLogContext.getLogger("").detach(Configurator.ATTACHMENT_KEY);
// If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
if (configurator instanceof PropertyConfigurator) {
final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
clearLogContext(logContextConfiguration);
} else if (configurator instanceof LogContextConfiguration) {
clearLogContext((LogContextConfiguration) configurator);
} else {
// Remove all the handlers and close them as well as reset the loggers
final List<String> loggerNames = Collections.list(embeddedLogContext.getLoggerNames());
for (String name : loggerNames) {
final Logger logger = embeddedLogContext.getLoggerIfExists(name);
if (logger != null) {
final Handler[] handlers = logger.clearHandlers();
if (handlers != null) {
for (Handler handler : handlers) {
handler.close();
}
}
logger.setFilter(null);
logger.setUseParentFilters(false);
logger.setUseParentHandlers(true);
logger.setLevel(Level.INFO);
}
}
}
}
use of org.jboss.logmanager.config.LogContextConfiguration in project activemq-artemis by rh-messaging.
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;
}
Aggregations