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();
}
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));
}
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();
}
}
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();
}
}
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();
}
Aggregations