use of org.jboss.logmanager.Configurator in project wildfly-core by wildfly.
the class EmbeddedLogContext method configureLogContext.
/**
* Configures the log context for the server and returns the configured log context.
*
* @param logDir the logging directory, from jboss.server|domain.log.dir standalone default {@code $JBOSS_HOME/standalone/log}
* @param configDir the configuration directory from jboss.server|domain.config.dir, standalone default {@code $JBOSS_HOME/standalone/configuration}
* @param defaultLogFileName the name of the log file to pass to {@code org.jboss.boot.log.file}
* @param ctx the command context used to report errors to
*
* @return the configured log context
*/
static synchronized LogContext configureLogContext(final File logDir, final File configDir, final String defaultLogFileName, final CommandContext ctx) {
final LogContext embeddedLogContext = Holder.LOG_CONTEXT;
final Path bootLog = logDir.toPath().resolve(Paths.get(defaultLogFileName));
final Path loggingProperties = configDir.toPath().resolve(Paths.get("logging.properties"));
if (Files.exists(loggingProperties)) {
WildFlySecurityManager.setPropertyPrivileged("org.jboss.boot.log.file", bootLog.toAbsolutePath().toString());
try (final InputStream in = Files.newInputStream(loggingProperties)) {
// Attempt to get the configurator from the root logger
Configurator configurator = embeddedLogContext.getAttachment("", Configurator.ATTACHMENT_KEY);
if (configurator == null) {
configurator = new PropertyConfigurator(embeddedLogContext);
final Configurator existing = embeddedLogContext.getLogger("").attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
if (existing != null) {
configurator = existing;
}
}
configurator.configure(in);
} catch (IOException e) {
ctx.printLine(String.format("Unable to configure logging from configuration file %s. Reason: %s", loggingProperties, e.getLocalizedMessage()));
}
}
return embeddedLogContext;
}
use of org.jboss.logmanager.Configurator in project wildfly-core by wildfly.
the class LoggingDeploymentResourceProcessor method deploy.
@Override
public final void deploy(final DeploymentPhaseContext phaseContext) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.hasAttachment(Attachments.MODULE)) {
LoggingConfigurationService loggingConfigurationService;
if (deploymentUnit.hasAttachment(LOGGING_CONFIGURATION_SERVICE_KEY)) {
loggingConfigurationService = deploymentUnit.getAttachment(LOGGING_CONFIGURATION_SERVICE_KEY);
// Remove the attachment as it should no longer be needed
deploymentUnit.removeAttachment(LOGGING_CONFIGURATION_SERVICE_KEY);
} else {
// Get the module
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
// Set the deployments class loader to ensure we get the correct log context
final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
LogContextConfiguration logContextConfiguration = null;
final LogContext logContext = LogContext.getLogContext();
final Configurator configurator = logContext.getAttachment(CommonAttributes.ROOT_LOGGER_NAME, Configurator.ATTACHMENT_KEY);
if (configurator instanceof LogContextConfiguration) {
logContextConfiguration = (LogContextConfiguration) configurator;
} else if (configurator instanceof PropertyConfigurator) {
logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
}
loggingConfigurationService = new LoggingConfigurationService(logContextConfiguration, "default");
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(current);
}
}
final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
// Register the resources
LoggingDeploymentResources.registerDeploymentResource(deploymentResourceSupport, loggingConfigurationService);
phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append("logging", "configuration"), loggingConfigurationService).install();
}
}
use of org.jboss.logmanager.Configurator in project wildfly-core by wildfly.
the class ConfigurationPersistence method getOrCreateConfigurationPersistence.
/**
* Gets the property configurator. If the {@link ConfigurationPersistence} does not exist a new one is created.
*
* @param logContext the log context used to find the property configurator or to attach it to.
*
* @return the property configurator
*/
public static ConfigurationPersistence getOrCreateConfigurationPersistence(final LogContext logContext) {
final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
final ConfigurationPersistence result;
synchronized (LOCK) {
Configurator configurator = root.getAttachment(Configurator.ATTACHMENT_KEY);
if (configurator == null) {
configurator = new ConfigurationPersistence(logContext);
Configurator existing = root.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
if (existing != null) {
configurator = existing;
}
}
if (configurator instanceof ConfigurationPersistence) {
// We have the correct configurator
result = (ConfigurationPersistence) configurator;
} else if (configurator instanceof PropertyConfigurator) {
// Create a new configurator delegating to the configurator found
result = new ConfigurationPersistence((PropertyConfigurator) configurator);
root.attach(Configurator.ATTACHMENT_KEY, result);
} else {
// An unknown configurator, log a warning and replace
LoggingLogger.ROOT_LOGGER.replacingConfigurator(configurator);
result = new ConfigurationPersistence(logContext);
root.attach(Configurator.ATTACHMENT_KEY, result);
}
}
return result;
}
use of org.jboss.logmanager.Configurator in project activemq-artemis by rh-messaging.
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.Configurator 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;
}
Aggregations