use of org.jboss.logmanager.PropertyConfigurator 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.PropertyConfigurator 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.PropertyConfigurator in project wildfly-core by wildfly.
the class BootableJar method configureLogContext.
private LogContext configureLogContext() throws IOException {
// Create our own log context instead of using the default system log context. This is useful for cases when the
// LogManager.readConfiguration() may be invoked it will not override the current configuration.
final LogContext logContext = LogContext.create();
final Path bootLog = environment.resolveLogDir(SERVER_LOG);
final Path loggingProperties = environment.resolveConfigurationDir(LOGGING_PROPERTIES);
if (Files.exists(loggingProperties)) {
try (final InputStream in = Files.newInputStream(loggingProperties)) {
environment.setSystemProperty(LOG_BOOT_FILE_PROP, bootLog.toAbsolutePath().toString());
// The LogManager.readConfiguration() uses the LogContext.getSystemLogContext(). Since we create our
// own LogContext we need to configure the context and attach the configurator to the root logger. The
// logging subsystem will use this configurator to determine what resources may need to be reconfigured.
PropertyConfigurator configurator = new PropertyConfigurator(logContext);
configurator.configure(in);
logContext.getLogger("").attach(Configurator.ATTACHMENT_KEY, configurator);
}
}
return logContext;
}
use of org.jboss.logmanager.PropertyConfigurator in project wildfly-core by wildfly.
the class CommandLineMain method configureLogManager.
private static void configureLogManager(final String[] args) {
// If the property is already set, we don't want to replace it
if (getSystemProperty("java.util.logging.manager") == null) {
try {
setSystemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
String logLevel = parseValue(getSystemProperty("jboss.cli.log.level"));
for (String arg : args) {
if (arg.startsWith("-Djboss.cli.log.level")) {
logLevel = parseValue(arg);
} else if (arg.startsWith("-Dlogging.configuration")) {
setSystemProperty("logging.configuration", parseValue(arg));
}
}
// The log level has not been set, no need to continue
if (logLevel == null)
return;
// Configure the log manager
final LogManager logManager = LogManager.getLogManager();
if (logManager instanceof org.jboss.logmanager.LogManager) {
// Attempt to configure based on defaults
logManager.readConfiguration();
// If configured a Configurator will be on the root logger
if (LogContext.getSystemLogContext().getAttachment("", Configurator.ATTACHMENT_KEY) == null) {
if (!"OFF".equalsIgnoreCase(logLevel)) {
try {
final PropertyConfigurator configurator = new PropertyConfigurator();
// Get the root logger and attach the configurator, note we don't need to be concerned with security exceptions
// as the logManager.readConfiguration() will have already failed the check
final Configurator appearing = LogContext.getSystemLogContext().getLogger("").attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
if (appearing == null) {
configurator.configure(createLogManagerConfig(logLevel));
}
} catch (IOException e) {
System.err.println("ERROR: Could not configure LogManager");
e.printStackTrace();
}
}
}
}
} catch (SecurityException e) {
System.err.println("ERROR: Could not configure LogManager");
e.printStackTrace();
} catch (Throwable ignored) {
}
}
}
Aggregations