use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.
the class BootableJar method configureLogging.
private void configureLogging() throws IOException {
if (!arguments.isVersion()) {
// Load the boot configuration properties
loadBootConfigProperties();
LogContext ctx = configureLogContext();
// Use our own LogContextSelector which returns the configured context.
LogContext.setLogContextSelector(() -> ctx);
// Make sure our original stdio is properly captured.
try {
Class.forName(org.jboss.logmanager.handlers.ConsoleHandler.class.getName(), true, org.jboss.logmanager.handlers.ConsoleHandler.class.getClassLoader());
} catch (Throwable ignored) {
}
// Install JBoss Stdio to avoid any nasty crosstalk, after command line arguments are processed.
StdioContext.install();
final StdioContext context = StdioContext.create(new NullInputStream(), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stdout"), org.jboss.logmanager.Level.INFO), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stderr"), org.jboss.logmanager.Level.ERROR));
StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));
}
}
use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.
the class LogController method getLoggers.
public static Json.JsonArrayBuilder getLoggers() {
LogContext logContext = LogContext.getLogContext();
TreeMap<String, Json.JsonObjectBuilder> loggerMap = new TreeMap<>();
Enumeration<String> loggerNames = logContext.getLoggerNames();
while (loggerNames.hasMoreElements()) {
String loggerName = loggerNames.nextElement();
Json.JsonObjectBuilder jsonObject = getLogger(loggerName);
if (jsonObject != null) {
loggerMap.put(loggerName, jsonObject);
}
}
List<Json.JsonObjectBuilder> orderedLoggers = new ArrayList<>(loggerMap.values());
Json.JsonArrayBuilder jsonArray = Json.array();
jsonArray.addAll(orderedLoggers);
return jsonArray;
}
use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.
the class LogController method getLogger.
public static Json.JsonObjectBuilder getLogger(String loggerName) {
LogContext logContext = LogContext.getLogContext();
if (loggerName != null && !loggerName.isEmpty()) {
Logger logger = logContext.getLogger(loggerName);
Json.JsonObjectBuilder jsonObject = Json.object();
jsonObject.put("name", loggerName);
jsonObject.put("effectiveLevel", getEffectiveLogLevel(logger));
jsonObject.put("configuredLevel", getConfiguredLogLevel(logger));
return jsonObject;
}
return null;
}
use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.
the class LoggingSetupRecorder method initializeBuildTimeLogging.
public static void initializeBuildTimeLogging(LogConfig config, LogBuildTimeConfig buildConfig, ConsoleRuntimeConfig consoleConfig, LaunchMode launchMode) {
final Map<String, CategoryConfig> categories = config.categories;
final LogContext logContext = LogContext.getLogContext();
final Logger rootLogger = logContext.getLogger("");
rootLogger.setLevel(config.level);
ErrorManager errorManager = new OnlyOnceErrorManager();
final Map<String, CleanupFilterConfig> filters = config.filters;
List<LogCleanupFilterElement> filterElements = new ArrayList<>(filters.size());
for (Entry<String, CleanupFilterConfig> entry : filters.entrySet()) {
filterElements.add(new LogCleanupFilterElement(entry.getKey(), entry.getValue().targetLevel, entry.getValue().ifStartsWith));
}
LogCleanupFilter logCleanupFilter = new LogCleanupFilter(filterElements);
final ArrayList<Handler> handlers = new ArrayList<>(3);
if (config.console.enable) {
final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager, logCleanupFilter, Collections.emptyList(), new RuntimeValue<>(Optional.empty()), launchMode);
errorManager = consoleHandler.getErrorManager();
handlers.add(consoleHandler);
}
Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, Collections.emptyList(), errorManager, logCleanupFilter, launchMode);
for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
final String categoryName = entry.getKey();
final Level logLevel = getLogLevel(categoryName, categories, CategoryConfig::getLevel, buildConfig.minLevel);
final Level minLogLevel = getLogLevel(categoryName, buildConfig.categories, CategoryBuildTimeConfig::getMinLevel, buildConfig.minLevel);
if (logLevel.intValue() < minLogLevel.intValue()) {
log.warnf("Log level %s for category '%s' set below minimum logging level %s, promoting it to %s", logLevel, entry.getKey(), minLogLevel, minLogLevel);
entry.getValue().level = InheritableLevel.of(minLogLevel.toString());
}
}
for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
final String name = entry.getKey();
final Logger categoryLogger = logContext.getLogger(name);
final CategoryConfig categoryConfig = entry.getValue();
if (!categoryConfig.level.isInherited()) {
categoryLogger.setLevel(categoryConfig.level.getLevel());
}
categoryLogger.setUseParentHandlers(categoryConfig.useParentHandlers);
if (categoryConfig.handlers.isPresent()) {
addNamedHandlersToCategory(categoryConfig, namedHandlers, categoryLogger, errorManager);
}
}
InitialConfigurator.DELAYED_HANDLER.setAutoFlush(false);
InitialConfigurator.DELAYED_HANDLER.setBuildTimeHandlers(handlers.toArray(EmbeddedConfigurator.NO_HANDLERS));
}
use of org.jboss.logmanager.LogContext in project kafka-admin-api by bf2fc6cc711aee1a0c2a.
the class LoggingConfigWatcher method delete.
private void delete() {
LogContext context = LogContext.getLogContext();
overriddenLoggers.forEach((category, originalLevel) -> {
org.jboss.logmanager.Logger logger = context.getLogger(category);
LOGGER.infof("Restoring original log level for logger %s: %s", category.isEmpty() ? "ROOT" : category, originalLevel);
if (originalLevel instanceof Inherit) {
originalLevel = null;
}
logger.setLevel(originalLevel);
});
overriddenLoggers.clear();
}
Aggregations