use of org.apache.log4j.ConsoleAppender in project apex-core by apache.
the class ApexCli method preImpersonationInit.
public void preImpersonationInit(String[] args) throws IOException {
Signal.handle(new Signal("INT"), new SignalHandler() {
@Override
public void handle(Signal sig) {
System.out.println("^C");
if (commandThread != null) {
commandThread.interrupt();
mainThread.interrupt();
} else {
System.out.print(prompt);
System.out.flush();
}
}
});
consolePresent = (System.console() != null);
Options options = new Options();
options.addOption("e", true, "Commands are read from the argument");
options.addOption("v", false, "Verbose mode level 1");
options.addOption("vv", false, "Verbose mode level 2");
options.addOption("vvv", false, "Verbose mode level 3");
options.addOption("vvvv", false, "Verbose mode level 4");
options.addOption("r", false, "JSON Raw mode");
options.addOption("p", true, "JSONP padding function");
options.addOption("h", false, "Print this help");
options.addOption("f", true, "Use the specified prompt at all time");
options.addOption("kp", true, "Use the specified kerberos principal");
options.addOption("kt", true, "Use the specified kerberos keytab");
CommandLineParser parser = new BasicParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("v")) {
verboseLevel = 1;
}
if (cmd.hasOption("vv")) {
verboseLevel = 2;
}
if (cmd.hasOption("vvv")) {
verboseLevel = 3;
}
if (cmd.hasOption("vvvv")) {
verboseLevel = 4;
}
if (cmd.hasOption("r")) {
raw = true;
}
if (cmd.hasOption("e")) {
commandsToExecute = cmd.getOptionValues("e");
consolePresent = false;
}
if (cmd.hasOption("p")) {
jsonp = cmd.getOptionValue("p");
}
if (cmd.hasOption("f")) {
forcePrompt = cmd.getOptionValue("f");
}
if (cmd.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(ApexCli.class.getSimpleName(), options);
System.exit(0);
}
if (cmd.hasOption("kp")) {
kerberosPrincipal = cmd.getOptionValue("kp");
}
if (cmd.hasOption("kt")) {
kerberosKeyTab = cmd.getOptionValue("kt");
}
} catch (ParseException ex) {
System.err.println("Invalid argument: " + ex);
System.exit(1);
}
if (kerberosPrincipal == null && kerberosKeyTab != null) {
System.err.println("Kerberos key tab is specified but not the kerberos principal. Please specify it using the -kp option.");
System.exit(1);
}
if (kerberosPrincipal != null && kerberosKeyTab == null) {
System.err.println("Kerberos principal is specified but not the kerberos key tab. Please specify it using the -kt option.");
System.exit(1);
}
Level logLevel;
switch(verboseLevel) {
case 0:
logLevel = Level.OFF;
break;
case 1:
logLevel = Level.ERROR;
break;
case 2:
logLevel = Level.WARN;
break;
case 3:
logLevel = Level.INFO;
break;
default:
logLevel = Level.DEBUG;
break;
}
for (org.apache.log4j.Logger logger : new org.apache.log4j.Logger[] { org.apache.log4j.Logger.getRootLogger(), org.apache.log4j.Logger.getLogger(ApexCli.class) }) {
/*
* Override logLevel specified by user, the same logLevel would be inherited by all
* appenders related to logger.
*/
logger.setLevel(logLevel);
@SuppressWarnings("unchecked") Enumeration<Appender> allAppenders = logger.getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender appender = allAppenders.nextElement();
if (appender instanceof ConsoleAppender) {
((ConsoleAppender) appender).setThreshold(logLevel);
}
}
}
if (commandsToExecute != null) {
for (String command : commandsToExecute) {
LOG.debug("Command to be executed: {}", command);
}
}
if (kerberosPrincipal != null && kerberosKeyTab != null) {
StramUserLogin.authenticate(kerberosPrincipal, kerberosKeyTab);
} else {
Configuration config = new YarnConfiguration();
StramClientUtils.addDTLocalResources(config);
StramUserLogin.attemptAuthentication(config);
}
}
use of org.apache.log4j.ConsoleAppender in project ignite by apache.
the class GridAbstractTest method resetLog4j.
/**
* Resets log4j programmatically.
*
* @param log4jLevel Level.
* @param logToFile If {@code true}, then log to file under "work/log" folder.
* @param cat Category.
* @param cats Additional categories.
*/
@SuppressWarnings({ "deprecation" })
protected void resetLog4j(Level log4jLevel, boolean logToFile, String cat, String... cats) throws IgniteCheckedException {
for (String c : F.concat(false, cat, F.asList(cats))) Logger.getLogger(c).setLevel(log4jLevel);
if (logToFile) {
Logger log4j = Logger.getRootLogger();
log4j.removeAllAppenders();
// Console appender.
ConsoleAppender c = new ConsoleAppender();
c.setName("CONSOLE_ERR");
c.setTarget("System.err");
c.setThreshold(Priority.WARN);
c.setLayout(new PatternLayout("[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"));
c.activateOptions();
log4j.addAppender(c);
// File appender.
RollingFileAppender file = new RollingFileAppender();
file.setName("FILE");
file.setThreshold(log4jLevel);
file.setFile(home() + "/work/log/ignite.log");
file.setAppend(false);
file.setMaxFileSize("10MB");
file.setMaxBackupIndex(10);
file.setLayout(new PatternLayout("[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"));
file.activateOptions();
log4j.addAppender(file);
}
}
use of org.apache.log4j.ConsoleAppender in project ignite by apache.
the class GridCacheAbstractLoadTest method initLogger.
/**
* Initializes logger.
*
* @param log Log file name.
* @return Logger.
* @throws IgniteCheckedException If file initialization failed.
*/
protected 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{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
try {
fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
fileApp.setMaxBackupIndex(0);
fileApp.setAppend(false);
// fileApp.rollOver();
fileApp.activateOptions();
} 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.DEBUG);
lvlFilter.setLevelMax(Level.INFO);
conApp.addFilter(lvlFilter);
conApp.activateOptions();
impl.addAppender(conApp);
// Configure output that should go to System.err
conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
conApp.setThreshold(Level.WARN);
conApp.activateOptions();
impl.addAppender(conApp);
impl.setLevel(Level.INFO);
return new GridTestLog4jLogger(false);
}
use of org.apache.log4j.ConsoleAppender 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{ABSOLUTE}][%-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.ConsoleAppender in project ignite by apache.
the class Log4JLogger method createConsoleAppender.
/**
* Creates console appender with some reasonable default logging settings.
*
* @param maxLevel Max logging level.
* @return New console appender.
*/
private Appender createConsoleAppender(Level maxLevel) {
String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
// Configure output that should go to System.out
Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.TRACE);
lvlFilter.setLevelMax(maxLevel);
app.addFilter(lvlFilter);
return app;
}
Aggregations