use of org.jboss.logmanager.LogContext in project kafka-admin-api by bf2fc6cc711aee1a0c2a.
the class LoggingConfigWatcher method modify.
private void modify(Path file) {
Properties properties = new Properties();
try (InputStream stream = Files.newInputStream(file)) {
properties.load(stream);
} catch (IOException e) {
LOGGER.warn("File {} cannot be read", file, e);
return;
}
LogContext context = LogContext.getLogContext();
properties.entrySet().stream().filter(this::isLogLevelConfiguration).map(entry -> toLoggerLevel(context, entry.getKey().toString(), entry.getValue().toString())).forEach(override -> {
org.jboss.logmanager.Logger logger = override.getKey();
String category = logger.getName();
Level level = override.getValue();
Level originalLevel = logger.getLevel() == null ? INHERIT : logger.getLevel();
LOGGER.infof("Overriding log level for category %s: %s => %s", category.isEmpty() ? "ROOT" : category, originalLevel, level);
// Save the original so that it can be restored if the override is removed
overriddenLoggers.computeIfAbsent(category, k -> originalLevel);
// TODO -- min-level handling? min-level is compile-time optimization
// See https://github.com/quarkusio/quarkus/blob/2.3.0.Final/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java#L92
// TODO -- Handle other category properties (besides .level)
// See https://quarkus.io/guides/logging#logging-categories
logger.setLevel(level);
});
}
use of org.jboss.logmanager.LogContext in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class LoggingConfigWatcher method updateLogLevel.
/**
* Taken from https://github.com/quarkusio/quarkus/blob/9861d4f0ccf61ed1fea4f067c309266ce07b0610/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogController.java#L78
* rather than introducing a full dependency
* @param loggerName
* @param levelValue
*/
public static void updateLogLevel(String loggerName, String levelValue) {
LogContext logContext = LogContext.getLogContext();
org.jboss.logmanager.Logger logger = logContext.getLogger(loggerName);
if (logger != null) {
java.util.logging.Level level = Level.parse(levelValue);
logger.setLevel(level);
log.infof("Log level updated [%s] changed to [%s]", loggerName, levelValue);
}
}
use of org.jboss.logmanager.LogContext in project activemq-artemis by apache.
the class LoggingConfigurationFileReloader method getOrCreateUpdater.
private LoggingConfigurationUpdater getOrCreateUpdater() {
final LogContext logContext = LogContext.getLogContext();
final org.jboss.logmanager.Logger rootLogger = logContext.getLogger("");
LoggingConfigurationUpdater updater = rootLogger.getAttachment(KEY);
if (updater == null) {
final LogContextConfiguration logContextConfiguration = getOrCreateConfiguration(rootLogger);
if (logContextConfiguration == null) {
return null;
}
updater = new LoggingConfigurationUpdater(logContextConfiguration);
final LoggingConfigurationUpdater appearing = rootLogger.attachIfAbsent(KEY, updater);
if (appearing != null) {
updater = appearing;
}
}
return updater;
}
use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.
the class LoggingSubsystemRollbackTestCase method rollbackUpdateAttribute.
public void rollbackUpdateAttribute(final String profileName) throws Exception {
// Save the current model
final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
// Add a handler to be removed
final PathAddress consoleHandler = createConsoleHandlerAddress(profileName, "CONSOLE");
// Create a new handler
ModelNode op = SubsystemOperations.createOperation(AbstractHandlerDefinition.CHANGE_LEVEL_OPERATION_NAME, consoleHandler.toModelNode());
op.get(CommonAttributes.LEVEL.getName()).set("DEBUG");
ModelNode result = kernelServices.executeOperation(op);
Assert.assertFalse("The update operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// verify the subsystem model matches the old model
ModelNode currentModel = getSubsystemModel(kernelServices);
compare(profileName, validSubsystemModel, currentModel);
final LogContext logContext = (profileName == null ? LogContext.getLogContext() : LoggingProfileContextSelector.getInstance().get(profileName));
ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(logContext);
compare(profileName, currentModel, config);
// Fail on a logger write attribute
final PathAddress rootLoggerAddress = createRootLoggerAddress(profileName);
op = SubsystemOperations.createOperation("change-root-log-level", rootLoggerAddress.toModelNode());
op.get(CommonAttributes.LEVEL.getName()).set("TRACE");
result = kernelServices.executeOperation(op);
Assert.assertFalse("The update operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// verify the subsystem model matches the old model
currentModel = getSubsystemModel(kernelServices);
compare(profileName, validSubsystemModel, currentModel);
config = ConfigurationPersistence.getConfigurationPersistence(logContext);
compare(profileName, currentModel, config);
}
use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.
the class LoggingSubsystemRollbackTestCase method rollbackRemove.
public void rollbackRemove(final String profileName) throws Exception {
// Save the current model
final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
final CompositeOperationBuilder compositeOperationBuilder = CompositeOperationBuilder.create();
// The handler address to remove
final PathAddress consoleHandler = createConsoleHandlerAddress(profileName, "CONSOLE");
// Remove the handler
compositeOperationBuilder.addStep(SubsystemOperations.createRemoveOperation(consoleHandler.toModelNode()));
// The logger to remove
final PathAddress loggerAddress = createLoggerAddress(profileName, "org.jboss.as.logging");
compositeOperationBuilder.addStep(SubsystemOperations.createRemoveOperation(loggerAddress.toModelNode()));
// Add a step to fail
final ModelNode rootLoggerAddress = createRootLoggerAddress(profileName).toModelNode();
compositeOperationBuilder.addStep(SubsystemOperations.createWriteAttributeOperation(rootLoggerAddress, CommonAttributes.LEVEL, "INFO"));
ModelNode result = kernelServices.executeOperation(compositeOperationBuilder.build().getOperation());
Assert.assertFalse("The update operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// verify the subsystem model matches the old model
ModelNode currentModel = getSubsystemModel(kernelServices);
compare(profileName, validSubsystemModel, currentModel);
final LogContext logContext = (profileName == null ? LogContext.getLogContext() : LoggingProfileContextSelector.getInstance().get(profileName));
ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(logContext);
compare(profileName, currentModel, config);
}
Aggregations