use of org.apache.log4j.PatternLayout in project databus by linkedin.
the class BootstrapDropSource method parseArgs.
@SuppressWarnings("static-access")
public static int 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 sourceIdOption = OptionBuilder.withLongOpt(SOURCE_ID_OPT_LONG_NAME).withDescription("Source ID for which tables need to be dropped").hasArg().withArgName("Source ID").create(SOURCE_ID_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 cmdLinePropsOption = OptionBuilder.withLongOpt(CMD_LINE_PROPS_OPT_LONG_NAME).withDescription("Cmd line override of config properties. Semicolon separated.").hasArg().withArgName("Semicolon_separated_properties").create(CMD_LINE_PROPS_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(sourceIdOption);
options.addOption(dbOption);
options.addOption(cmdLinePropsOption);
options.addOption(log4jPropsOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
LOG.error("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(SOURCE_ID_OPT_CHAR))
throw new RuntimeException("Source ID is not provided");
if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
throw new RuntimeException("Bootstrap config is not provided");
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
_sBootstrapConfigProps = new Properties();
FileInputStream f = new FileInputStream(propFile);
try {
_sBootstrapConfigProps.load(f);
} finally {
f.close();
}
if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR)) {
String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR);
updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
}
return Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR));
}
use of org.apache.log4j.PatternLayout in project openolat by klemens.
the class Log4JInitServlet method init.
@Override
public void init() {
String file = getInitParameter("log4j-init-file");
ClassPathResource res = new ClassPathResource(file);
if (!res.exists()) {
// creating basic log4j configuration which writes to console out, Only called when not yet configured
ConsoleAppender appender = new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"), ConsoleAppender.SYSTEM_OUT);
appender.setThreshold(Level.INFO);
BasicConfigurator.configure(appender);
OLog log = Tracing.createLoggerFor(getClass());
log.info("*****************************************************************************************");
log.info("You don't provide a log4j config file for your OLAT instance. OLAT will just log to standard out (e.g. catalina.out)." + " Please provide a proper log config file (log4j.xml, see olat/conf for an example or read the installation guide) " + "and place it into the root of the classpath e.g. tomcat/lib or WEB-INF/classes");
log.info("*****************************************************************************************");
}
}
use of org.apache.log4j.PatternLayout in project ignite by apache.
the class GridSingleExecutionTest method initLogger.
/**
* Initializes logger.
*
* @param log Log file name.
* @return Logger.
* @throws IgniteCheckedException If file initialization failed.
*/
private static IgniteLogger initLogger(String log) throws IgniteCheckedException {
Logger impl = Logger.getRootLogger();
impl.removeAllAppenders();
String fileName = U.getIgniteHome() + "/work/log/" + log;
// Configure output that should go to System.out
RollingFileAppender fileApp;
String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
try {
fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
fileApp.setMaxBackupIndex(0);
fileApp.rollOver();
} catch (IOException e) {
throw new IgniteCheckedException("Unable to initialize file appender.", e);
}
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.DEBUG);
fileApp.addFilter(lvlFilter);
impl.addAppender(fileApp);
// Configure output that should go to System.out
ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.INFO);
lvlFilter.setLevelMax(Level.INFO);
conApp.addFilter(lvlFilter);
impl.addAppender(conApp);
// Configure output that should go to System.err
conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
conApp.setThreshold(Level.WARN);
impl.addAppender(conApp);
impl.setLevel(Level.INFO);
Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG);
return new GridTestLog4jLogger(false);
}
use of org.apache.log4j.PatternLayout in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method setUp.
@Before
public void setUp() {
org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
metacard.setMetadata(TEST_METADATA);
plugin = new XmlAttributeSecurityPolicyPlugin();
List<String> attributeUnions = Arrays.asList("controls", "marker");
List<String> attributeIntersections = Arrays.asList("countries");
List<String> xmlElements = Arrays.asList("title", "creator", "security");
plugin.setXmlElements(xmlElements);
plugin.setSecurityAttributeUnions(attributeUnions);
plugin.setSecurityAttributeIntersections(attributeIntersections);
}
use of org.apache.log4j.PatternLayout in project metron by apache.
the class UnitTestHelper method verboseLogging.
public static void verboseLogging(String pattern, Level level) {
// create appender
ConsoleAppender console = new ConsoleAppender();
// configure the appender
console.setLayout(new PatternLayout(pattern));
console.setThreshold(level);
console.activateOptions();
// add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
}
Aggregations