Search in sources :

Example 1 with Configurator

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;
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) Configurator(org.jboss.logmanager.Configurator) LogContext(org.jboss.logmanager.LogContext) IOException(java.io.IOException) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Example 2 with Configurator

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();
    }
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) Configurator(org.jboss.logmanager.Configurator) LogContext(org.jboss.logmanager.LogContext) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Example 3 with Configurator

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;
}
Also used : PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) Configurator(org.jboss.logmanager.Configurator) Logger(org.jboss.logmanager.Logger) LoggingLogger(org.jboss.as.logging.logging.LoggingLogger) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Example 4 with Configurator

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;
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) Configurator(org.jboss.logmanager.Configurator) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Example 5 with Configurator

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;
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) Configurator(org.jboss.logmanager.Configurator) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator) PropertyConfigurator(org.jboss.logmanager.PropertyConfigurator)

Aggregations

Configurator (org.jboss.logmanager.Configurator)7 PropertyConfigurator (org.jboss.logmanager.PropertyConfigurator)7 LogContextConfiguration (org.jboss.logmanager.config.LogContextConfiguration)4 LogContext (org.jboss.logmanager.LogContext)3 IOException (java.io.IOException)2 Logger (org.jboss.logmanager.Logger)2 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 List (java.util.List)1 Handler (java.util.logging.Handler)1 LogManager (java.util.logging.LogManager)1 LoggingLogger (org.jboss.as.logging.logging.LoggingLogger)1 DeploymentResourceSupport (org.jboss.as.server.deployment.DeploymentResourceSupport)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 Module (org.jboss.modules.Module)1