Search in sources :

Example 56 with Logger

use of ch.qos.logback.classic.Logger in project springside4 by springside.

the class LogbackListAppender method addToLogger.

/**
 * 将此appender添加到logger中.
 */
public void addToLogger(String loggerName) {
    Logger logger = (Logger) LoggerFactory.getLogger(loggerName);
    logger.addAppender(this);
}
Also used : Logger(ch.qos.logback.classic.Logger)

Example 57 with Logger

use of ch.qos.logback.classic.Logger in project springside4 by springside.

the class LogbackListAppender method removeFromLogger.

/**
 * 将此appender从logger中移除.
 */
public void removeFromLogger(Class<?> loggerClass) {
    Logger logger = (Logger) LoggerFactory.getLogger(loggerClass);
    logger.detachAppender(this);
}
Also used : Logger(ch.qos.logback.classic.Logger)

Example 58 with Logger

use of ch.qos.logback.classic.Logger in project gocd by gocd.

the class FileLocationProvider method asJson.

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    json.put("loc.config.dir", systemEnvironment.configDir().getAbsolutePath());
    List<Logger> loggers = LOGGER_CONTEXT.getLoggerList();
    Appender[] appenders = getAppenders(loggers);
    for (int i = 0; i < appenders.length; i++) {
        Appender appender = appenders[i];
        if (!isFileAppender(appender)) {
            continue;
        }
        FileAppender fileAppender = (FileAppender) appender;
        File logFile = new File(fileAppender.rawFileProperty());
        json.put("loc.log.root." + i, new File(logFile.getAbsolutePath()).getParent());
        json.put("loc.log.basename." + i, logFile.getName());
    }
    return json;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) Logger(ch.qos.logback.classic.Logger) File(java.io.File)

Example 59 with Logger

use of ch.qos.logback.classic.Logger in project drools-wb by kiegroup.

the class IndexGlobalsInvalidDrlTest method testIndexGlobalsInvalidDrl.

@Test
@SuppressWarnings("unchecked")
public void testIndexGlobalsInvalidDrl() throws IOException, InterruptedException {
    // Setup logging
    final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Appender<ILoggingEvent> mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    // Add test file
    final Path path = basePath.resolve("bz1269366.gdrl");
    final String drl = loadText("bz1269366.gdrl");
    ioService().write(path, drl);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.util.ArrayList", ResourceType.JAVA)).build();
        searchFor(index, query, 0);
        verify(mockAppender).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {

            @Override
            public boolean matches(final Object argument) {
                return ((ILoggingEvent) argument).getMessage().startsWith("Unable to parse DRL");
            }
        }));
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 60 with Logger

use of ch.qos.logback.classic.Logger in project drools-wb by kiegroup.

the class IndexDslInvalidDrlTest method testIndexDslInvalidDrl.

@Test
public void testIndexDslInvalidDrl() throws IOException, InterruptedException {
    // Setup logging
    final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Appender<ILoggingEvent> mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    // Add test files
    final Path path = basePath.resolve("bz1269366.dsl");
    final String dsl = loadText("bz1269366.dsl");
    ioService().write(path, dsl);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.dsltext.backend.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 0);
        verify(mockAppender).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {

            @Override
            public boolean matches(final Object argument) {
                return ((ILoggingEvent) argument).getMessage().startsWith("Unable to parse DRL");
            }
        }));
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Aggregations

Logger (ch.qos.logback.classic.Logger)144 Test (org.junit.Test)49 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)45 LoggerContext (ch.qos.logback.classic.LoggerContext)40 FileAppender (ch.qos.logback.core.FileAppender)17 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)16 Appender (ch.qos.logback.core.Appender)16 File (java.io.File)13 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 ArrayList (java.util.ArrayList)9 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)8 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)8 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)7 Before (org.junit.Before)7 PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)6 Query (org.apache.lucene.search.Query)6 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)6 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)6 Level (ch.qos.logback.classic.Level)5 Map (java.util.Map)5