本文整理汇总了Java中org.jboss.logmanager.LogContext类的典型用法代码示例。如果您正苦于以下问题:Java LogContext类的具体用法?Java LogContext怎么用?Java LogContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogContext类属于org.jboss.logmanager包,在下文中一共展示了LogContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStdioContext
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Override
public StdioContext getStdioContext() {
final LogContext logContext = LogContext.getLogContext();
final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
StdioContext stdioContext = root.getAttachment(STDIO_CONTEXT_ATTACHMENT_KEY);
if (stdioContext == null) {
stdioContext = StdioContext.create(
new NullInputStream(),
new LoggingOutputStream(logContext.getLogger("stdout"), Level.INFO),
new LoggingOutputStream(logContext.getLogger("stderr"), Level.ERROR)
);
final StdioContext appearing = root.attachIfAbsent(STDIO_CONTEXT_ATTACHMENT_KEY, stdioContext);
if (appearing != null) {
stdioContext = appearing;
}
}
return stdioContext;
}
示例2: deploy
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Override
public final void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// If the log context is already defined, skip the rest of the processing
if (!hasRegisteredLogContext(deploymentUnit)) {
if (deploymentUnit.hasAttachment(Attachments.MODULE) && deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_ROOT)) {
// don't process sub-deployments as they are processed by processing methods
final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (SubDeploymentMarker.isSubDeployment(root)) return;
processDeployment(phaseContext, deploymentUnit, root);
// If we still don't have a context registered on the root deployment, register the current context.
// This is done to avoid any logging from the root deployment to have access to a sub-deployments log
// context. For example any library logging from a EAR/lib should use the EAR's configured log context,
// not a log context from a WAR or EJB library.
if (!hasRegisteredLogContext(deploymentUnit) && !deploymentUnit.hasAttachment(DEFAULT_LOG_CONTEXT_KEY)) {
// Register the current log context as this could be an embedded server or overridden another way
registerLogContext(deploymentUnit, DEFAULT_LOG_CONTEXT_KEY, deploymentUnit.getAttachment(Attachments.MODULE), LogContext.getLogContext());
}
}
}
}
示例3: registerLogContext
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
private void registerLogContext(final DeploymentUnit deploymentUnit, final AttachmentKey<LogContext> attachmentKey, final Module module, final LogContext logContext) {
LoggingLogger.ROOT_LOGGER.tracef("Registering LogContext %s for deployment %s", logContext, deploymentUnit.getName());
if (WildFlySecurityManager.isChecking()) {
WildFlySecurityManager.doUnchecked(new PrivilegedAction<Object>() {
@Override
public Object run() {
logContextSelector.registerLogContext(module.getClassLoader(), logContext);
return null;
}
});
} else {
logContextSelector.registerLogContext(module.getClassLoader(), logContext);
}
// Add the log context to the sub-deployment unit for later removal
deploymentUnit.putAttachment(attachmentKey, logContext);
}
示例4: unregisterLogContext
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
private void unregisterLogContext(final DeploymentUnit deploymentUnit, final AttachmentKey<LogContext> attachmentKey, final Module module) {
final LogContext logContext = deploymentUnit.removeAttachment(attachmentKey);
if (logContext != null) {
final boolean success;
if (WildFlySecurityManager.isChecking()) {
success = WildFlySecurityManager.doUnchecked(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return logContextSelector.unregisterLogContext(module.getClassLoader(), logContext);
}
});
} else {
success = logContextSelector.unregisterLogContext(module.getClassLoader(), logContext);
}
if (success) {
LoggingLogger.ROOT_LOGGER.tracef("Removed LogContext '%s' from '%s'", logContext, module);
} else {
LoggingLogger.ROOT_LOGGER.logContextNotRemoved(logContext, deploymentUnit.getName());
}
}
}
示例5: applyUpdateToRuntime
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Override
protected final boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<ConfigurationPersistence> handbackHolder) throws OperationFailedException {
final String name = getAddressName(operation);
final PathAddress address = getAddress(operation);
final ConfigurationPersistence configurationPersistence;
final boolean isLoggingProfile = LoggingProfileOperations.isLoggingProfileAddress(address);
if (isLoggingProfile) {
final LogContext logContext = LoggingProfileContextSelector.getInstance().getOrCreate(LoggingProfileOperations.getLoggingProfileName(address));
configurationPersistence = ConfigurationPersistence.getOrCreateConfigurationPersistence(logContext);
} else {
configurationPersistence = ConfigurationPersistence.getOrCreateConfigurationPersistence();
}
final LogContextConfiguration logContextConfiguration = configurationPersistence.getLogContextConfiguration();
handbackHolder.setHandback(configurationPersistence);
final boolean restartRequired = applyUpdate(context, attributeName, name, resolvedValue, logContextConfiguration);
addCommitStep(context, configurationPersistence);
return restartRequired;
}
示例6: testConfiguration
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Test
public void testConfiguration() throws Exception {
final KernelServices kernelServices = boot();
final ModelNode currentModel = getSubsystemModel(kernelServices);
compare(currentModel, ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext()));
// Compare properties written out to current model
final String dir = resolveRelativePath(kernelServices, "jboss.server.config.dir");
Assert.assertNotNull("jboss.server.config.dir could not be resolved", dir);
final LogContext logContext = LogContext.create();
final ConfigurationPersistence config = ConfigurationPersistence.getOrCreateConfigurationPersistence(logContext);
try (final FileInputStream in = new FileInputStream(new File(dir, "logging.properties"))) {
config.configure(in);
compare(currentModel, config);
}
}
示例7: restoreLogContextSelector
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
synchronized void restoreLogContextSelector() {
if (!logContextSelectorRestored) {
final LogContext logContext = defaultContexts.getLogContext();
if (logContext == LogContext.getSystemLogContext()) {
LogContext.setLogContextSelector(LogContext.DEFAULT_LOG_CONTEXT_SELECTOR);
} else {
LogContext.setLogContextSelector(new LogContextSelector() {
@Override
public LogContext getLogContext() {
return logContext;
}
});
}
EmbeddedLogContext.clearLogContext();
logContextSelectorRestored = true;
}
}
示例8: getOrCreateConfigurationPersistence
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
/**
* Gets the property configurator. If the {@link ConfigurationPersistence} does not exist a new one is created.
*
* @param logContext the log context used to find the property configurator or to attach it to.
*
* @return the property configurator
*/
public static ConfigurationPersistence getOrCreateConfigurationPersistence(final LogContext logContext) {
final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
final ConfigurationPersistence result;
synchronized (LOCK) {
Configurator configurator = root.getAttachment(Configurator.ATTACHMENT_KEY);
if (configurator == null) {
configurator = new ConfigurationPersistence(logContext);
Configurator existing = root.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
if (existing != null) {
configurator = existing;
}
}
if (configurator instanceof ConfigurationPersistence) {
// We have the correct configurator
result = (ConfigurationPersistence) configurator;
} else if (configurator instanceof PropertyConfigurator) {
// Create a new configurator delegating to the configurator found
result = new ConfigurationPersistence((PropertyConfigurator) configurator);
root.attach(Configurator.ATTACHMENT_KEY, result);
} else {
// An unknown configurator, log a warning and replace
LoggingLogger.ROOT_LOGGER.replacingConfigurator(configurator);
result = new ConfigurationPersistence(logContext);
root.attach(Configurator.ATTACHMENT_KEY, result);
}
}
return result;
}
示例9: WildFlyLogContextSelectorImpl
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
public WildFlyLogContextSelectorImpl() {
counter = new AtomicInteger(0);
// Use the current log context as the default, not LogContext.DEFAULT_LOG_CONTEXT_SELECTOR
// This allows embedding use cases to control the log context
final LogContext defaultLogContext = LogContext.getLogContext();
contextSelector = new ClassLoaderLogContextSelector(new LogContextSelector() {
@Override
public LogContext getLogContext() {
return defaultLogContext;
}
}, true);
threadLocalContextSelector = new ThreadLocalLogContextSelector(contextSelector);
}
示例10: unregisterLogContext
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Override
public boolean unregisterLogContext(final ClassLoader classLoader, final LogContext logContext) {
if (contextSelector.unregisterLogContext(classLoader, logContext)) {
counter.decrementAndGet();
return true;
}
return false;
}
示例11: getOrCreate
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
/**
* 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;
}
示例12: getLogger
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
private Logger getLogger(final String profileName) {
final LogContext logContext;
if (profileName != null) {
logContext = LoggingProfileContextSelector.getInstance().get(profileName);
} else {
logContext = LogContext.getSystemLogContext();
}
return logContext.getLogger(FQCN);
}
示例13: testRollbackLogger
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Test
@BMRule(name = "Test logger rollback handler",
targetClass = "org.jboss.as.logging.LoggerOperations$LoggerAddOperationStepHandler",
targetMethod = "performRuntime",
targetLocation = "AT EXIT",
condition = "$4.equals(\"org.jboss.as.logging.test\")",
action = "$1.setRollbackOnly()"
)
public void testRollbackLogger() throws Exception {
final KernelServices kernelServices = boot();
// Save the current model
final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
// The logger address
final PathAddress address = createLoggerAddress("org.jboss.as.logging.test");
// Operation should fail based on byteman script
ModelNode op = SubsystemOperations.createAddOperation(address.toModelNode());
ModelNode result = kernelServices.executeOperation(op);
Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// Verify the loggers are not there - operation should fail on missing resource
op = SubsystemOperations.createReadResourceOperation(address.toModelNode());
result = kernelServices.executeOperation(op);
Assert.assertFalse("The operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// verify the subsystem model matches the old model
final ModelNode currentModel = getSubsystemModel(kernelServices);
compare(validSubsystemModel, currentModel);
final ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
compare(currentModel, config);
}
示例14: testRollbackHandler
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Test
@BMRule(name = "Test handler rollback handler",
targetClass = "org.jboss.as.logging.HandlerOperations$HandlerAddOperationStepHandler",
targetMethod = "performRuntime",
targetLocation = "AT EXIT",
condition = "$4.equals(\"CONSOLE2\")",
action = "$1.setRollbackOnly()")
public void testRollbackHandler() throws Exception {
final KernelServices kernelServices = boot();
// Save the current model
final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
// Handler address
final PathAddress address = createConsoleHandlerAddress("CONSOLE2");
// Operation should fail based on byteman script
ModelNode op = SubsystemOperations.createAddOperation(address.toModelNode());
op.get(CommonAttributes.LEVEL.getName()).set("INFO");
op.get(AbstractHandlerDefinition.FORMATTER.getName()).set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) CONSOLE2: %s%e%n");
ModelNode result = kernelServices.executeOperation(op);
Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// Verify the loggers are not there - operation should fail on missing resource
op = SubsystemOperations.createReadResourceOperation(address.toModelNode());
result = kernelServices.executeOperation(op);
Assert.assertFalse("The operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
// verify the subsystem model matches the old model
final ModelNode currentModel = getSubsystemModel(kernelServices);
compare(validSubsystemModel, currentModel);
final ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
compare(currentModel, config);
}
示例15: testRollbackRemoveProfile
import org.jboss.logmanager.LogContext; //导入依赖的package包/类
@Test
@BMRules(rules = {
@BMRule(name = "Test handler write-attribute rollback handler",
targetClass = "org.jboss.as.logging.LoggerOperations$LoggerWriteAttributeHandler",
targetMethod = "applyUpdate",
targetLocation = "AT EXIT",
condition = "$3.equals(\"ROOT\")",
action = "$1.setRollbackOnly()")
})
public void testRollbackRemoveProfile() throws Exception {
final KernelServices kernelServices = boot();
// Save the current model
final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
final CompositeOperationBuilder compositeOperationBuilder = CompositeOperationBuilder.create();
// The handler address to remove
final PathAddress profileAddress = createAddress(CommonAttributes.LOGGING_PROFILE, PROFILE_NAME);
// Remove the handler
compositeOperationBuilder.addStep(SubsystemOperations.createRemoveOperation(profileAddress.toModelNode(), true));
// Add a step to fail
final ModelNode rootLoggerAddress = createRootLoggerAddress().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
final ModelNode currentModel = getSubsystemModel(kernelServices);
compare(validSubsystemModel, currentModel);
ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
compare(currentModel, config);
// Check the profile was rolled back
config = ConfigurationPersistence.getConfigurationPersistence(LoggingProfileContextSelector.getInstance().get(PROFILE_NAME));
compare(PROFILE_NAME, currentModel, config);
}