use of org.jboss.logmanager.Configurator 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.Configurator 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