Search in sources :

Example 61 with Logger

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

the class IndexRuleInvalidDrlTest method testIndexRuleInvalidDrl.

@Test
public void testIndexRuleInvalidDrl() 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.tdrl");
    final String drl = loadText("bz1269366.tdrl");
    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 ValueResourceIndexTerm("*myRule", ResourceType.RULE, TermSearchType.WILDCARD)).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) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 62 with Logger

use of ch.qos.logback.classic.Logger in project cdap by caskdata.

the class CLIMain method main.

public static void main(String[] args) {
    // disable logback logging
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.OFF);
    final PrintStream output = System.out;
    Options options = getOptions();
    CLIMainArgs cliMainArgs = CLIMainArgs.parse(args, options);
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine command = parser.parse(options, cliMainArgs.getOptionTokens());
        if (command.hasOption(HELP_OPTION.getOpt())) {
            usage();
            System.exit(0);
        }
        LaunchOptions launchOptions = LaunchOptions.builder().setUri(command.getOptionValue(URI_OPTION.getOpt(), getDefaultURI().toString())).setDebug(command.hasOption(DEBUG_OPTION.getOpt())).setVerifySSL(parseBooleanOption(command, VERIFY_SSL_OPTION, DEFAULT_VERIFY_SSL)).setAutoconnect(parseBooleanOption(command, AUTOCONNECT_OPTION, DEFAULT_AUTOCONNECT)).build();
        String scriptFile = command.getOptionValue(SCRIPT_OPTION.getOpt(), "");
        boolean hasScriptFile = command.hasOption(SCRIPT_OPTION.getOpt());
        String[] commandArgs = cliMainArgs.getCommandTokens();
        try {
            ClientConfig clientConfig = ClientConfig.builder().setConnectionConfig(null).setDefaultReadTimeout(parseIntegerOption(command, TIMEOUT_OPTION, 60) * 1000).build();
            final CLIConfig cliConfig = new CLIConfig(clientConfig, output, new AltStyleTableRenderer());
            CLIMain cliMain = new CLIMain(launchOptions, cliConfig);
            CLI cli = cliMain.getCLI();
            if (!cliMain.tryAutoconnect(command)) {
                System.exit(0);
            }
            CLIConnectionConfig connectionConfig = new CLIConnectionConfig(cliConfig.getClientConfig().getConnectionConfig(), cliConfig.getCurrentNamespace(), null);
            cliMain.updateCLIPrompt(connectionConfig);
            if (hasScriptFile) {
                File script = cliMain.getFilePathResolver().resolvePathToFile(scriptFile);
                if (!script.exists()) {
                    output.println("ERROR: Script file '" + script.getAbsolutePath() + "' does not exist");
                    System.exit(1);
                }
                List<String> scriptLines = Files.readLines(script, Charsets.UTF_8);
                for (String scriptLine : scriptLines) {
                    output.print(cliMain.getPrompt(connectionConfig));
                    output.println(scriptLine);
                    cli.execute(scriptLine, output);
                    output.println();
                }
            } else if (commandArgs.length == 0) {
                cli.startInteractiveMode(output);
            } else {
                cli.execute(Joiner.on(" ").join(commandArgs), output);
            }
        } catch (DisconnectedException e) {
            output.printf("Couldn't reach the CDAP instance at '%s'.", e.getConnectionConfig().getURI().toString());
        } catch (Exception e) {
            e.printStackTrace(output);
        }
    } catch (ParseException e) {
        output.println(e.getMessage());
        usage();
    }
}
Also used : PrintStream(java.io.PrintStream) Options(org.apache.commons.cli.Options) CLI(co.cask.common.cli.CLI) AltStyleTableRenderer(co.cask.cdap.cli.util.table.AltStyleTableRenderer) Logger(ch.qos.logback.classic.Logger) URISyntaxException(java.net.URISyntaxException) DisconnectedException(co.cask.cdap.client.exception.DisconnectedException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) InvalidCommandException(co.cask.common.cli.exception.InvalidCommandException) ParseException(org.apache.commons.cli.ParseException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) ClientConfig(co.cask.cdap.client.config.ClientConfig) File(java.io.File) DisconnectedException(co.cask.cdap.client.exception.DisconnectedException)

Example 63 with Logger

use of ch.qos.logback.classic.Logger in project dubbo by alibaba.

the class LogbackContainer method doInitializer.

/**
 * Initializer logback
 *
 * @param file
 * @param level
 * @param maxHistory
 */
private void doInitializer(String file, String level, int maxHistory) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.detachAndStopAllAppenders();
    // appender
    RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(loggerContext);
    fileAppender.setName("application");
    fileAppender.setFile(file);
    fileAppender.setAppend(true);
    // policy
    TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
    policy.setContext(loggerContext);
    policy.setMaxHistory(maxHistory);
    policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
    policy.setParent(fileAppender);
    policy.start();
    fileAppender.setRollingPolicy(policy);
    // encoder
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
    encoder.start();
    fileAppender.setEncoder(encoder);
    fileAppender.start();
    rootLogger.addAppender(fileAppender);
    rootLogger.setLevel(Level.toLevel(level));
    rootLogger.setAdditive(false);
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy)

Example 64 with Logger

use of ch.qos.logback.classic.Logger in project cdap-ingest by caskdata.

the class FileTailerIT method fileTailerNoLogsBeforeStartIT.

@Test
public void fileTailerNoLogsBeforeStartIT() throws Exception {
    File configFile = getConfigFile();
    PipeConfiguration pipeConfig = loadConfig(configFile);
    String logFilePath = pipeConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + pipeConfig.getSourceConfiguration().getFileName();
    Logger logger = getTimeLogger(logFilePath);
    PipeManager manager = new PipeManager(configFile);
    mockMetricsProcessor(manager);
    long startTime = System.currentTimeMillis();
    manager.startAsync();
    Thread.sleep(SLEEP_TIME);
    writeLogs(logger, ENTRY_NUMBER);
    Thread.sleep(SLEEP_TIME);
    logger.getAppender("File Tailer IT").stop();
    manager.stopAsync();
    Thread.sleep(SLEEP_TIME);
    Assert.assertEquals(read.get(), ingest.get());
    checkDeliveredEvents(ENTRY_NUMBER, startTime);
}
Also used : PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) Logger(ch.qos.logback.classic.Logger) File(java.io.File) Test(org.junit.Test)

Example 65 with Logger

use of ch.qos.logback.classic.Logger in project cdap-ingest by caskdata.

the class FileTailerIT method fileTailerBasicIT.

@Test
public void fileTailerBasicIT() throws Exception {
    File configFile = getConfigFile();
    PipeConfiguration pipeConfig = loadConfig(configFile);
    String logFilePath = pipeConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/" + pipeConfig.getSourceConfiguration().getFileName();
    Logger logger = getTimeLogger(logFilePath);
    writeLogs(logger, ENTRY_NUMBER);
    PipeManager manager = new PipeManager(configFile);
    mockMetricsProcessor(manager);
    long startTime = System.currentTimeMillis();
    manager.startAsync();
    writeLogs(logger, ENTRY_NUMBER);
    Thread.sleep(SLEEP_TIME);
    logger.getAppender("File Tailer IT").stop();
    manager.stopAsync();
    Thread.sleep(SLEEP_TIME);
    Assert.assertEquals(read.get(), ingest.get());
    checkDeliveredEvents(ENTRY_NUMBER * 2, startTime);
}
Also used : PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) Logger(ch.qos.logback.classic.Logger) File(java.io.File) Test(org.junit.Test)

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