use of org.jboss.logmanager.LogContext 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.LogContext in project wildfly-core by wildfly.
the class LoggingOperations method getConfigurationPersistence.
private static ConfigurationPersistence getConfigurationPersistence(final OperationContext context) {
final PathAddress address = context.getCurrentAddress();
final LogContext logContext;
if (LoggingProfileOperations.isLoggingProfileAddress(address)) {
logContext = LoggingProfileContextSelector.getInstance().get(LoggingProfileOperations.getLoggingProfileName(address));
} else {
logContext = LogContext.getLogContext();
}
return ConfigurationPersistence.getConfigurationPersistence(logContext);
}
use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.
the class LoggingOperations method getOrCreateConfigurationPersistence.
private static ConfigurationPersistence getOrCreateConfigurationPersistence(final OperationContext context) {
final PathAddress address = context.getCurrentAddress();
final ConfigurationPersistence configurationPersistence;
if (LoggingProfileOperations.isLoggingProfileAddress(address)) {
final LogContext logContext = LoggingProfileContextSelector.getInstance().getOrCreate(LoggingProfileOperations.getLoggingProfileName(address));
configurationPersistence = ConfigurationPersistence.getOrCreateConfigurationPersistence(logContext);
} else {
configurationPersistence = ConfigurationPersistence.getOrCreateConfigurationPersistence();
}
return configurationPersistence;
}
use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.
the class LoggingProfileContextSelector method getOrCreate.
/**
* Get or create the log context based on the logging profile.
*
* @param loggingProfile the logging profile to get or create the log context for
*
* @return the log context that was found or a new log context
*/
protected LogContext getOrCreate(final String loggingProfile) {
LogContext result = profileContexts.get(loggingProfile);
if (result == null) {
result = LogContext.create();
final LogContext current = profileContexts.putIfAbsent(loggingProfile, result);
if (current != null) {
result = current;
}
}
return result;
}
use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.
the class LoggingSetupRecorder method initializeLogging.
public void initializeLogging(LogConfig config, LogBuildTimeConfig buildConfig, final boolean enableWebStream, final RuntimeValue<Optional<Handler>> devUiConsoleHandler, final List<RuntimeValue<Optional<Handler>>> additionalHandlers, final List<RuntimeValue<Map<String, Handler>>> additionalNamedHandlers, final List<RuntimeValue<Optional<Formatter>>> possibleFormatters, final RuntimeValue<Optional<Supplier<String>>> possibleBannerSupplier, LaunchMode launchMode) {
final Map<String, CategoryConfig> categories = config.categories;
final LogContext logContext = LogContext.getLogContext();
final Logger rootLogger = logContext.getLogger("");
if (config.level.intValue() < buildConfig.minLevel.intValue()) {
log.warnf("Root log level %s set below minimum logging level %s, promoting it to %s", config.level, buildConfig.minLevel, buildConfig.minLevel);
rootLogger.setLevel(buildConfig.minLevel);
} else {
rootLogger.setLevel(config.level);
}
ErrorManager errorManager = new OnlyOnceErrorManager();
final Map<String, CleanupFilterConfig> filters = config.filters;
List<LogCleanupFilterElement> filterElements;
if (filters.isEmpty()) {
filterElements = Collections.emptyList();
} else {
filterElements = new ArrayList<>(filters.size());
filters.forEach(new BiConsumer<String, CleanupFilterConfig>() {
@Override
public void accept(String loggerName, CleanupFilterConfig config) {
filterElements.add(new LogCleanupFilterElement(loggerName, config.targetLevel, config.ifStartsWith));
}
});
}
LogCleanupFilter cleanupFiler = new LogCleanupFilter(filterElements);
for (Handler handler : LogManager.getLogManager().getLogger("").getHandlers()) {
handler.setFilter(cleanupFiler);
}
final ArrayList<Handler> handlers = new ArrayList<>(3 + additionalHandlers.size());
if (config.console.enable) {
final Handler consoleHandler = configureConsoleHandler(config.console, consoleRuntimeConfig.getValue(), errorManager, cleanupFiler, possibleFormatters, possibleBannerSupplier, launchMode);
errorManager = consoleHandler.getErrorManager();
handlers.add(consoleHandler);
}
if (launchMode.isDevOrTest()) {
handlers.add(new Handler() {
@Override
public void publish(LogRecord record) {
if (record.getThrown() != null) {
ExceptionReporting.notifyException(record.getThrown());
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
});
}
if (config.file.enable) {
handlers.add(configureFileHandler(config.file, errorManager, cleanupFiler));
}
if (config.syslog.enable) {
final Handler syslogHandler = configureSyslogHandler(config.syslog, errorManager, cleanupFiler);
if (syslogHandler != null) {
handlers.add(syslogHandler);
}
}
if ((launchMode.isDevOrTest() || enableWebStream) && devUiConsoleHandler != null && devUiConsoleHandler.getValue().isPresent()) {
Handler handler = devUiConsoleHandler.getValue().get();
handler.setErrorManager(errorManager);
handler.setFilter(new LogCleanupFilter(filterElements));
if (possibleBannerSupplier != null && possibleBannerSupplier.getValue().isPresent()) {
Supplier<String> bannerSupplier = possibleBannerSupplier.getValue().get();
String header = "\n" + bannerSupplier.get();
handler.publish(new LogRecord(Level.INFO, header));
}
handlers.add(handler);
}
if (!categories.isEmpty()) {
Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleRuntimeConfig.getValue(), possibleFormatters, errorManager, cleanupFiler, launchMode);
Map<String, Handler> additionalNamedHandlersMap;
if (additionalNamedHandlers.isEmpty()) {
additionalNamedHandlersMap = Collections.emptyMap();
} else {
additionalNamedHandlersMap = new HashMap<>();
for (RuntimeValue<Map<String, Handler>> runtimeValue : additionalNamedHandlers) {
runtimeValue.getValue().forEach(new AdditionalNamedHandlersConsumer(additionalNamedHandlersMap, errorManager, filterElements));
}
}
namedHandlers.putAll(additionalNamedHandlersMap);
categories.forEach(new BiConsumer<String, CategoryConfig>() {
@Override
public void accept(String categoryName, CategoryConfig config) {
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, categoryName, minLogLevel, minLogLevel);
config.level = InheritableLevel.of(minLogLevel.toString());
}
}
});
categories.forEach(new CategoryLoggerConsumer(logContext, namedHandlers, errorManager));
}
for (RuntimeValue<Optional<Handler>> additionalHandler : additionalHandlers) {
final Optional<Handler> optional = additionalHandler.getValue();
if (optional.isPresent()) {
final Handler handler = optional.get();
handler.setErrorManager(errorManager);
handler.setFilter(cleanupFiler);
handlers.add(handler);
}
}
InitialConfigurator.DELAYED_HANDLER.setAutoFlush(false);
InitialConfigurator.DELAYED_HANDLER.setHandlers(handlers.toArray(EmbeddedConfigurator.NO_HANDLERS));
}
Aggregations