本文整理了Java中org.apache.logging.log4j.core.Appender.getName()
方法的一些代码示例,展示了Appender.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Appender.getName()
方法的具体详情如下:
包路径:org.apache.logging.log4j.core.Appender
类名称:Appender
方法名:getName
[英]Gets the name of this Appender.
[中]获取此追加器的名称。
代码示例来源:origin: apache/ignite
for (Appender appender : log.getAppenders().values()) {
if (appender instanceof ConsoleAppender) {
if ("CONSOLE_ERR".equals(appender.getName()))
continue;
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testLogger() throws Exception {
final Logger logger = this.ctx.getLogger(LOGGER_NAME);
assertThat(logger, is(instanceOf(org.apache.logging.log4j.core.Logger.class)));
final org.apache.logging.log4j.core.Logger l = (org.apache.logging.log4j.core.Logger) logger;
assertThat(l.getLevel(), is(equalTo(Level.DEBUG)));
assertThat(l.filterCount(), is(equalTo(1)));
final Iterator<Filter> iterator = l.getFilters();
assertThat(iterator.hasNext(), is(true));
final Filter filter = iterator.next();
assertThat(filter, is(instanceOf(ThreadContextMapFilter.class)));
final Map<String, Appender> appenders = l.getAppenders();
assertThat(appenders, is(notNullValue()));
assertThat(appenders.size(), is(equalTo(1)));
final Appender appender = appenders.get(APPENDER_NAME);
assertThat(appender, is(notNullValue()));
assertThat(appender.getName(), is(equalTo("STDOUT")));
}
代码示例来源:origin: javamelody/javamelody
void deregister() {
if (LogManager.getContext(false) instanceof LoggerContext) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
if (ctx.getConfiguration() instanceof AbstractConfiguration) {
final AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
final Appender appender = getSingleton();
appender.stop();
config.removeAppender(appender.getName());
final Logger rootLogger = LogManager.getRootLogger();
final LoggerConfig loggerConfig = config.getLoggerConfig(rootLogger.getName());
loggerConfig.removeAppender(appender.getName());
ctx.updateLoggers();
}
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testLogger() throws Exception {
final Logger logger = this.ctx.getLogger(LOGGER_NAME);
assertThat(logger, is(instanceOf(org.apache.logging.log4j.core.Logger.class)));
final org.apache.logging.log4j.core.Logger l = (org.apache.logging.log4j.core.Logger) logger;
assertThat(l.getLevel(), is(equalTo(Level.DEBUG)));
assertThat(l.filterCount(), is(equalTo(1)));
final Iterator<Filter> iterator = l.getFilters();
assertThat(iterator.hasNext(), is(true));
final Filter filter = iterator.next();
assertThat(filter, is(instanceOf(ThreadContextMapFilter.class)));
final Map<String, Appender> appenders = l.getAppenders();
assertThat(appenders, is(notNullValue()));
assertThat(appenders, hasSize(1));
final Appender appender = appenders.get(APPENDER_NAME);
assertThat(appender, is(notNullValue()));
assertThat(appender.getName(), is(equalTo("STDOUT")));
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAsync(List<Object[]> args) {
Map<String, Appender> appenders = logger.getAppenders();
if (appenders == null) {
throw new IllegalStateException("Activate async appender failed, no appender exist.");
}
AppenderRef[] refs = new AppenderRef[appenders.size()];
int i = 0;
for (Appender appender : appenders.values()) {
configuration.addAppender(appender);
refs[i++] = AppenderRef.createAppenderRef(appender.getName(), null, null);
}
AsyncAppender.Builder builder = AsyncAppender.newBuilder()
.setName(productName + "." + logger.getName() + ".AsyncAppender")
.setConfiguration(configuration)
.setAppenderRefs(refs)
.setBlockingQueueFactory(ArrayBlockingQueueFactory.<LogEvent>createFactory());
invokeMethod(builder, args);
AsyncAppender asyncAppender = builder.build();
asyncAppender.start();
removeAllAppenders(logger);
logger.addAppender(asyncAppender);
setProductName(productName);
}
代码示例来源:origin: mulesoft/mule
private void removeAppender(LoggerContext context, Appender appender) {
((AbstractConfiguration) context.getConfiguration()).removeAppender(appender.getName());
}
}
代码示例来源:origin: mulesoft/mule
private void removeAppender(LoggerContext context, Function<Appender, Boolean> appenderMatcher) {
for (Appender appender : getRootLogger(context).getAppenders().values()) {
if (appenderMatcher.apply(appender)) {
removeAppender(context, appender);
getRootLogger(context).removeAppender(appender.getName());
}
}
}
代码示例来源:origin: mulesoft/mule
@Override
public void run() {
contextConfigurer.update(context);
ArgumentCaptor<ConsoleAppender> appenderCaptor = ArgumentCaptor.forClass(ConsoleAppender.class);
verify(context.getConfiguration()).addAppender(appenderCaptor.capture());
Appender forcedConsoleAppender = appenderCaptor.getValue();
assertThat(forcedConsoleAppender, notNullValue());
assertThat(forcedConsoleAppender.getName(), equalTo(FORCED_CONSOLE_APPENDER_NAME));
assertThat(forcedConsoleAppender.isStarted(), is(true));
LoggerConfig rootLogger = ((AbstractConfiguration) context.getConfiguration()).getRootLogger();
verify(rootLogger).addAppender(forcedConsoleAppender, Level.ALL, null);
}
});
代码示例来源:origin: mulesoft/mule
@Test
public void perAppDefaultAppender() throws Exception {
when(context.isArtifactClassloader()).thenReturn(true);
when(context.getArtifactDescriptor().getDeploymentProperties()).thenReturn(empty());
contextConfigurer.update(context);
ArgumentCaptor<RollingFileAppender> appenderCaptor = ArgumentCaptor.forClass(RollingFileAppender.class);
verify(context.getConfiguration()).addAppender(appenderCaptor.capture());
Appender perAppAppender = appenderCaptor.getValue();
assertThat(perAppAppender, notNullValue());
assertThat(perAppAppender.getName(), equalTo(PER_APP_FILE_APPENDER_NAME));
assertThat(perAppAppender.isStarted(), is(true));
String filePattern = ClassUtils.getFieldValue(perAppAppender, FILE_PATTERN_PROPERTY, true);
String filePatternTemplate = filePattern.substring(filePattern.lastIndexOf('/') + 1);
String filePatternTemplateDateSuffix = filePatternTemplate.substring(filePatternTemplate.lastIndexOf('.') + 1);
assertThat(filePatternTemplateDateSuffix, equalTo(FILE_PATTERN_TEMPLATE_DATE_SECTION));
LoggerConfig rootLogger = context.getConfiguration().getRootLogger();
verify(rootLogger).addAppender(perAppAppender, Level.ALL, null);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static void removeAppender(final Logger logger, final Appender appender) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
if (!logger.getName().equals(loggerConfig.getName())) {
loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
config.addLogger(logger.getName(), loggerConfig);
}
loggerConfig.removeAppender(appender.getName());
ctx.updateLoggers();
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
/**
* Adds an Appender to the configuration.
*
* @param appender The Appender to add.
*/
@Override
public void addAppender(final Appender appender) {
appenders.putIfAbsent(appender.getName(), appender);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
/**
* This method is not exposed through the public API and is used primarily for unit testing.
*
* @param appender The Appender to remove from the Logger.
*/
public void removeAppender(final Appender appender) {
privateConfig.loggerConfig.removeAppender(appender.getName());
}
代码示例来源:origin: org.mule.modules/mule-module-launcher
private void removeAppender(LoggerContext context, Appender appender)
{
((AbstractConfiguration) context.getConfiguration()).removeAppender(appender.getName());
}
}
代码示例来源:origin: org.mule.runtime/mule-module-launcher
private void removeAppender(LoggerContext context, Function<Appender, Boolean> appenderMatcher) {
for (Appender appender : getRootLogger(context).getAppenders().values()) {
if (appenderMatcher.apply(appender)) {
removeAppender(context, appender);
getRootLogger(context).removeAppender(appender.getName());
}
}
}
代码示例来源:origin: org.mule.modules/mule-module-launcher
private void removeConsoleAppender(LoggerContext context)
{
for (Appender appender : getRootLogger(context).getAppenders().values())
{
if (appender instanceof ConsoleAppender)
{
removeAppender(context, appender);
getRootLogger(context).removeAppender(appender.getName());
}
}
}
代码示例来源:origin: com.mchange/mchange-commons-java
@Override
public void removeHandler(Object h) throws SecurityException
{
if(!(h instanceof Appender))
throw new IllegalArgumentException("The 'handler' " + h + " is not compatible with MLogger " + this);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(this.logger.getName());
loggerConfig.removeAppender(((Appender) h).getName());
ctx.updateLoggers();
}
代码示例来源:origin: kptfh/feign-reactive
@Before
public void before() {
appender = Mockito.mock(Appender.class);
when(appender.getName()).thenReturn("TestAppender");
when(appender.isStarted()).thenReturn(true);
getLoggerConfig().addAppender(appender, Level.ALL, null);
}
代码示例来源:origin: apache/servicemix-bundles
public static void removeAppender(final Logger logger, final Appender appender) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
if (!logger.getName().equals(loggerConfig.getName())) {
loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
config.addLogger(logger.getName(), loggerConfig);
}
loggerConfig.removeAppender(appender.getName());
ctx.updateLoggers();
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
public static void removeAppender(final Logger logger, final Appender appender) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
if (!logger.getName().equals(loggerConfig.getName())) {
loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
config.addLogger(logger.getName(), loggerConfig);
}
loggerConfig.removeAppender(appender.getName());
ctx.updateLoggers();
}
代码示例来源:origin: info.magnolia/magnolia-core
/**
* Removes the given appender from the root logger; typically upon tear-down (@After).
*/
public static void stopRecordingLogs(Appender appender) {
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
String appenderName = appender.getName();
if (config.getAppenders().remove(appenderName) != null) {
appender.stop();
config.getRootLogger().removeAppender(appenderName);
context.updateLoggers(config);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!