Search in sources :

Example 1 with SimpleLayout

use of org.apache.log4j.SimpleLayout in project databus by linkedin.

the class AvroConvertCli method main.

/**
   * @param args
   */
public static void main(String[] args) throws Exception {
    ConsoleAppender app = new ConsoleAppender(new SimpleLayout());
    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(app);
    AvroConvertCli cli = new AvroConvertCli();
    try {
        cli.parseCommandLine(args);
    } catch (ParseException pe) {
        System.err.println(pe.getMessage());
        cli.printUsage();
        System.exit(1);
    }
    if (!cli.hasOptions() || cli.hasHelpOption()) {
        cli.printUsage();
        System.exit(0);
    }
    int verbosity = cli.getVerbosity();
    switch(verbosity) {
        case 0:
            Logger.getRootLogger().setLevel(Level.ERROR);
            break;
        case 1:
            Logger.getRootLogger().setLevel(Level.INFO);
            break;
        case 2:
            Logger.getRootLogger().setLevel(Level.DEBUG);
            break;
        default:
            Logger.getRootLogger().setLevel(Level.ALL);
            break;
    }
    AvroFormat inputFormat = cli.getInputFormat(AvroFormat.JSON);
    LOG.info("Using input format: " + inputFormat);
    AvroFormat outputFormat = cli.getOutputFormat(AvroFormat.JSON);
    LOG.info("Using output format: " + outputFormat);
    String inputSchemaName = cli.getInputSchema(null);
    if (null == inputSchemaName) {
        System.err.println("Input schema expected");
        cli.printUsage();
        System.exit(4);
    }
    Schema inputSchema = null;
    try {
        inputSchema = openSchema(inputSchemaName);
    } catch (IOException ioe) {
        System.err.println("Unable to open input schema: " + ioe);
        System.exit(2);
    }
    LOG.info("Using input schema:" + inputSchemaName);
    String outputSchemaName = cli.getOutputSchema(inputSchemaName);
    Schema outputSchema = null;
    try {
        outputSchema = outputSchemaName.equals(inputSchemaName) ? inputSchema : openSchema(outputSchemaName);
    } catch (IOException ioe) {
        System.err.println("Unable to open output schema: " + ioe);
        System.exit(3);
    }
    LOG.info("Using output schema:" + outputSchemaName);
    String inputFileName = cli.getInputFileName("-");
    InputStream input = inputFileName.equals("-") ? System.in : new FileInputStream(inputFileName);
    LOG.info("Using input: " + inputFileName);
    String outputFileName = cli.getOutputFileName("-");
    OutputStream output = outputFileName.equals("-") ? System.out : new FileOutputStream(outputFileName);
    LOG.info("Using output: " + outputFileName);
    AvroConverter avroConverter = new AvroConverter(inputFormat, outputFormat, inputSchema, outputSchema);
    avroConverter.convert(input, output);
    if (!inputFileName.equals("-"))
        input.close();
    if (!outputFileName.equals("-"))
        output.close();
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) AvroFormat(com.linkedin.databus2.core.schema.tools.AvroConverter.AvroFormat) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Schema(org.apache.avro.Schema) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SimpleLayout(org.apache.log4j.SimpleLayout) FileOutputStream(java.io.FileOutputStream) ParseException(org.apache.commons.cli.ParseException)

Example 2 with SimpleLayout

use of org.apache.log4j.SimpleLayout in project databus by linkedin.

the class TestFilterToSQL method setUp.

@BeforeClass
public void setUp() throws IOException, DatabusException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
    Logger.getRootLogger().removeAllAppenders();
    Appender defApp = new ConsoleAppender(new SimpleLayout());
    Logger.getRootLogger().addAppender(defApp);
    Logger.getRootLogger().setLevel(Level.INFO);
    BootstrapServerConfig configBuilder = new BootstrapServerConfig();
    BootstrapServerStaticConfig staticConfig = configBuilder.build();
    processor = new BootstrapProcessor(staticConfig, null);
    partConf = new KeyFilterConfigHolder.Config();
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) BootstrapServerConfig(com.linkedin.databus.bootstrap.server.BootstrapServerConfig) BootstrapProcessor(com.linkedin.databus.bootstrap.server.BootstrapProcessor) KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) SimpleLayout(org.apache.log4j.SimpleLayout) BootstrapServerStaticConfig(com.linkedin.databus.bootstrap.server.BootstrapServerStaticConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with SimpleLayout

use of org.apache.log4j.SimpleLayout in project ddf by codice.

the class ReliableResourceInputStreamTest method testInputStreamReadRetry.

@Test
public void testInputStreamReadRetry() throws Exception {
    LOGGER.info("Testing testInputStreamReadTwice()");
    ReliableResourceInputStream is = new ReliableResourceInputStream(fbos, countingFbos, downloadState, downloadIdentifier, resourceResponse);
    is.setCallableAndItsFuture(reliableResourceCallable, downloadFuture);
    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(is.getClass());
    logger.setLevel(Level.TRACE);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Layout layout = new SimpleLayout();
    Appender appender = new WriterAppender(layout, out);
    logger.addAppender(appender);
    //downloadState.setDownloadState(DownloadManagerState.DownloadState.IN_PROGRESS);
    try {
        // Write zero bytes to FileBackedOutputStream
        byte[] bytes = new String("").getBytes();
        countingFbos.write(bytes, 0, bytes.length);
        // Attempt to read from FileBackedOutputStream
        final byte[] buffer = new byte[50];
        int numBytesRead = is.read(buffer, 0, 50);
        // Verify bytes read is -1
        assertThat(numBytesRead, is(-1));
        // Verify read inputstream performed twice
        String logMsg = out.toString();
        assertThat(logMsg, is(notNullValue()));
        assertThat(logMsg, containsString("First time reading inputstream"));
    //assertThat(logMsg, containsString("Retry reading inputstream"));
    } finally {
        logger.removeAppender(appender);
    }
}
Also used : Appender(org.apache.log4j.Appender) WriterAppender(org.apache.log4j.WriterAppender) SimpleLayout(org.apache.log4j.SimpleLayout) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 4 with SimpleLayout

use of org.apache.log4j.SimpleLayout in project hadoop by apache.

the class TestYARNRunner method testWarnCommandOpts.

@Test(timeout = 20000)
public void testWarnCommandOpts() throws Exception {
    Logger logger = Logger.getLogger(YARNRunner.class);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Layout layout = new SimpleLayout();
    Appender appender = new WriterAppender(layout, bout);
    logger.addAppender(appender);
    JobConf jobConf = new JobConf();
    jobConf.set(MRJobConfig.MR_AM_ADMIN_COMMAND_OPTS, "-Djava.net.preferIPv4Stack=true -Djava.library.path=foo");
    jobConf.set(MRJobConfig.MR_AM_COMMAND_OPTS, "-Xmx1024m -Djava.library.path=bar");
    YARNRunner yarnRunner = new YARNRunner(jobConf);
    @SuppressWarnings("unused") ApplicationSubmissionContext submissionContext = buildSubmitContext(yarnRunner, jobConf);
    String logMsg = bout.toString();
    assertTrue(logMsg.contains("WARN - Usage of -Djava.library.path in " + "yarn.app.mapreduce.am.admin-command-opts can cause programs to no " + "longer function if hadoop native libraries are used. These values " + "should be set as part of the LD_LIBRARY_PATH in the app master JVM " + "env using yarn.app.mapreduce.am.admin.user.env config settings."));
    assertTrue(logMsg.contains("WARN - Usage of -Djava.library.path in " + "yarn.app.mapreduce.am.command-opts can cause programs to no longer " + "function if hadoop native libraries are used. These values should " + "be set as part of the LD_LIBRARY_PATH in the app master JVM env " + "using yarn.app.mapreduce.am.env config settings."));
}
Also used : WriterAppender(org.apache.log4j.WriterAppender) Appender(org.apache.log4j.Appender) SimpleLayout(org.apache.log4j.SimpleLayout) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Example 5 with SimpleLayout

use of org.apache.log4j.SimpleLayout in project ignite by apache.

the class GridNodeMetricsLogSelfTest method testNodeMetricsLog.

/**
     * @throws Exception If failed.
     */
public void testNodeMetricsLog() throws Exception {
    // Log to string, to check log content
    Layout layout = new SimpleLayout();
    StringWriter strWr = new StringWriter();
    WriterAppender app = new WriterAppender(layout, strWr);
    Logger.getRootLogger().addAppender(app);
    Ignite g1 = startGrid(1);
    IgniteCache<Integer, String> cache1 = g1.createCache("TestCache1");
    cache1.put(1, "one");
    Ignite g2 = startGrid(2);
    IgniteCache<Integer, String> cache2 = g2.createCache("TestCache2");
    cache2.put(2, "two");
    Thread.sleep(10_000);
    //Check that nodes are alie
    assertEquals("one", cache1.get(1));
    assertEquals("two", cache2.get(2));
    String fullLog = strWr.toString();
    Logger.getRootLogger().removeAppender(app);
    assert fullLog.contains("Metrics for local node");
    assert fullLog.contains("uptime=");
    assert fullLog.contains("Non heap");
    assert fullLog.contains("Outbound messages queue");
}
Also used : SimpleLayout(org.apache.log4j.SimpleLayout) StringWriter(java.io.StringWriter) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) Ignite(org.apache.ignite.Ignite) WriterAppender(org.apache.log4j.WriterAppender)

Aggregations

SimpleLayout (org.apache.log4j.SimpleLayout)6 WriterAppender (org.apache.log4j.WriterAppender)4 Appender (org.apache.log4j.Appender)3 Layout (org.apache.log4j.Layout)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 StringWriter (java.io.StringWriter)2 ConsoleAppender (org.apache.log4j.ConsoleAppender)2 Test (org.junit.Test)2 BootstrapProcessor (com.linkedin.databus.bootstrap.server.BootstrapProcessor)1 BootstrapServerConfig (com.linkedin.databus.bootstrap.server.BootstrapServerConfig)1 BootstrapServerStaticConfig (com.linkedin.databus.bootstrap.server.BootstrapServerStaticConfig)1 KeyFilterConfigHolder (com.linkedin.databus2.core.filter.KeyFilterConfigHolder)1 AvroFormat (com.linkedin.databus2.core.schema.tools.AvroConverter.AvroFormat)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Schema (org.apache.avro.Schema)1 ParseException (org.apache.commons.cli.ParseException)1