Search in sources :

Example 1 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender 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 ConsoleAppender

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

the class ScnIndex method printVerboseString.

//
// print each block's content from the index
// if the same offset - consolidate into one line
// also (to save disk space and improve readability) - use simplified log format
public void printVerboseString(Logger log, Level l) {
    // create a temp logger with simplified message
    //PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
    PatternLayout defaultLayout = new PatternLayout("%m%n");
    ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
    Logger newLog = Logger.getLogger("Simple");
    newLog.removeAllAppenders();
    newLog.addAppender(defaultAppender);
    newLog.setAdditivity(false);
    newLog.setLevel(Level.ALL);
    log.log(l, toString());
    if (!isEnabled()) {
        log.log(l, "ScnIndex is disabled");
        return;
    }
    // consolidated printing:
    //     beginBlock-endBlock:SCN=>Offset
    // actual line is printed only when offset changes
    long currentOffset, beginBlock;
    long endBlock;
    long currentScn = -1;
    currentOffset = -1;
    endBlock = beginBlock = 0;
    newLog.log(l, "logger name: " + log.getName() + " ts:" + (new Date()));
    for (int position = 0; position < buffer.limit(); position += SIZE_OF_SCN_OFFSET_RECORD) {
        long nextOffset = getOffset(position);
        if (currentOffset < 0)
            currentOffset = nextOffset;
        long nextBlock = position / SIZE_OF_SCN_OFFSET_RECORD;
        long nextScn = getScn(position);
        if (currentScn < 0)
            currentScn = nextScn;
        if (nextOffset != currentOffset || currentScn != nextScn) {
            // new offset - print the previous line
            newLog.log(l, buildBlockIndexString(beginBlock, endBlock, currentScn, currentOffset));
            currentOffset = nextOffset;
            beginBlock = nextBlock;
            currentScn = nextScn;
        }
        endBlock = nextBlock;
    //log.log(p, i/SIZE_OF_SCN_OFFSET_RECORD + ":" + nextScn + "->" + nextOffset);
    }
    // final line
    newLog.log(l, buildBlockIndexString(beginBlock, endBlock, currentScn, currentOffset));
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) Logger(org.apache.log4j.Logger) Date(java.util.Date)

Example 3 with ConsoleAppender

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

the class BootstrapAvroFileSeederMain method parseArgs.

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();
    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
    Option sourcesOption = OptionBuilder.withLongOpt(PHYSICAL_CONFIG_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(PHYSICAL_CONFIG_OPT_CHAR);
    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME).withDescription("Log4j properties to use").hasArg().withArgName("property_file").create(LOG4J_PROPS_OPT_CHAR);
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourcesOption);
    options.addOption(dbOption);
    options.addOption(log4jPropsOption);
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }
    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);
        //using info as the default log level
        Logger.getRootLogger().setLevel(Level.INFO);
        LOG.info("Using default logging settings. Log Level is :" + Logger.getRootLogger().getLevel());
    }
    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }
    if (!cmd.hasOption(PHYSICAL_CONFIG_OPT_CHAR))
        throw new RuntimeException("Sources Config is not provided; use --help for usage");
    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");
    _sSourcesConfigFile = cmd.getOptionValue(PHYSICAL_CONFIG_OPT_CHAR);
    String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile);
    _sBootstrapConfigProps = new Properties();
    FileInputStream fis = new FileInputStream(propFile);
    try {
        _sBootstrapConfigProps.load(fis);
    } finally {
        fis.close();
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PatternLayout(org.apache.log4j.PatternLayout) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 4 with ConsoleAppender

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

the class BootstrapTableReader method parseArgs.

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();
    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
    Option sourcesOption = OptionBuilder.withLongOpt(QUERY_CONFIG_OPT_LONG_NAME).withDescription("Query Config").hasArg().withArgName("property_file").create(QUERY_CONFIG_OPT_CHAR);
    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap DB properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME).withDescription("Log4j properties to use").hasArg().withArgName("property_file").create(LOG4J_PROPS_OPT_CHAR);
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourcesOption);
    options.addOption(dbOption);
    options.addOption(log4jPropsOption);
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }
    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);
        LOG.info("Using default logging settings");
    }
    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }
    if (!cmd.hasOption(QUERY_CONFIG_OPT_CHAR)) {
        throw new RuntimeException("Query Config is not provided; use --help for usage");
    }
    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) {
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");
    }
    String propFile1 = cmd.getOptionValue(QUERY_CONFIG_OPT_CHAR);
    String propFile2 = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile2);
    _sQueryConfigProps = new Properties();
    FileInputStream f1 = new FileInputStream(propFile1);
    try {
        _sQueryConfigProps.load(f1);
    } finally {
        f1.close();
    }
    _sBootstrapConfigProps = new Properties();
    FileInputStream f2 = new FileInputStream(propFile2);
    try {
        _sBootstrapConfigProps.load(f2);
    } finally {
        f2.close();
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PatternLayout(org.apache.log4j.PatternLayout) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 5 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender 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)

Aggregations

ConsoleAppender (org.apache.log4j.ConsoleAppender)32 PatternLayout (org.apache.log4j.PatternLayout)23 ParseException (org.apache.commons.cli.ParseException)9 FileAppender (org.apache.log4j.FileAppender)9 Logger (org.apache.log4j.Logger)9 IOException (java.io.IOException)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)8 Appender (org.apache.log4j.Appender)8 FileInputStream (java.io.FileInputStream)7 CommandLine (org.apache.commons.cli.CommandLine)7 GnuParser (org.apache.commons.cli.GnuParser)7 Options (org.apache.commons.cli.Options)7 Properties (java.util.Properties)6 Option (org.apache.commons.cli.Option)6 Enumeration (java.util.Enumeration)4 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)3 RollingFileAppender (org.apache.log4j.RollingFileAppender)3 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)2