use of org.apache.log4j.PatternLayout in project BiglyBT by BiglySoftware.
the class Log method execute.
@Override
public void execute(String commandName, final ConsoleInput ci, CommandLine commandLine) {
Appender con = Logger.getRootLogger().getAppender("ConsoleAppender");
List args = commandLine.getArgList();
if ((con != null) && (!args.isEmpty())) {
String subcommand = (String) args.get(0);
if ("off".equalsIgnoreCase(subcommand)) {
if (args.size() == 1) {
con.addFilter(new DenyAllFilter());
ci.out.println("> Console logging off");
} else {
String name = (String) args.get(1);
Object[] entry = (Object[]) channel_listener_map.remove(name);
if (entry == null) {
ci.out.println("> Channel '" + name + "' not being logged");
} else {
((LoggerChannel) entry[0]).removeListener((LoggerChannelListener) entry[1]);
ci.out.println("> Channel '" + name + "' logging off");
}
}
} else if ("on".equalsIgnoreCase(subcommand)) {
if (args.size() == 1) {
if (commandLine.hasOption('f')) {
// send log output to a file
String filename = commandLine.getOptionValue('f');
try {
Appender newAppender = new FileAppender(new PatternLayout("%d{ISO8601} %c{1}-%p: %m%n"), filename, true);
newAppender.setName("ConsoleAppender");
Logger.getRootLogger().removeAppender(con);
Logger.getRootLogger().addAppender(newAppender);
ci.out.println("> Logging to filename: " + filename);
} catch (IOException e) {
ci.out.println("> Unable to log to file: " + filename + ": " + e);
}
} else {
if (!(con instanceof ConsoleAppender)) {
Logger.getRootLogger().removeAppender(con);
con = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN));
con.setName("ConsoleAppender");
Logger.getRootLogger().addAppender(con);
}
// switch back to console appender
ci.out.println("> Console logging on");
}
con.clearFilters();
} else {
// hack - dunno how to do plugin-specific logging using these damn appenders..
Map channel_map = getChannelMap(ci);
final String name = (String) args.get(1);
LoggerChannel channel = (LoggerChannel) channel_map.get(name);
if (channel == null) {
ci.out.println("> Channel '" + name + "' not found");
} else if (channel_listener_map.get(name) != null) {
ci.out.println("> Channel '" + name + "' already being logged");
} else {
LoggerChannelListener l = new LoggerChannelListener() {
@Override
public void messageLogged(int type, String content) {
ci.out.println("[" + name + "] " + content);
}
@Override
public void messageLogged(String str, Throwable error) {
ci.out.println("[" + name + "] " + str);
error.printStackTrace(ci.out);
}
};
channel.addListener(l);
channel_listener_map.put(name, new Object[] { channel, l });
ci.out.println("> Channel '" + name + "' on");
}
}
} else if (subcommand.equalsIgnoreCase("list")) {
Map channel_map = getChannelMap(ci);
Iterator it = channel_map.keySet().iterator();
while (it.hasNext()) {
String name = (String) it.next();
ci.out.println(" " + name + " [" + (channel_listener_map.get(name) == null ? "off" : "on") + "]");
}
} else {
ci.out.println("> Command 'log': Subcommand '" + subcommand + "' unknown.");
}
} else {
ci.out.println("> Console logger not found or missing subcommand for 'log'\r\n> log syntax: log [-f filename] (on [name]|off [name]|list)");
}
}
use of org.apache.log4j.PatternLayout in project tez by apache.
the class Utils method setupRootLogger.
public static void setupRootLogger() {
if (Strings.isNullOrEmpty(System.getProperty(LOG4J_CONFIGURATION))) {
// By default print to console with INFO level
Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
Logger.getRootLogger().setLevel(Level.INFO);
}
}
use of org.apache.log4j.PatternLayout in project incubator-rya by apache.
the class DemoDriver method setupLogging.
private static void setupLogging() {
// Turn off all the loggers and customize how they write to the console.
final Logger rootLogger = LogManager.getRootLogger();
rootLogger.setLevel(Level.OFF);
final ConsoleAppender ca = (ConsoleAppender) rootLogger.getAppender("stdout");
ca.setLayout(new PatternLayout("%-5p - %m%n"));
// Turn the loggers used by the demo back on.
log.setLevel(Level.INFO);
}
use of org.apache.log4j.PatternLayout in project incubator-rya by apache.
the class RyaClientExample method setupLogging.
private static void setupLogging() {
// Turn off all the loggers and customize how they write to the console.
final Logger rootLogger = LogManager.getRootLogger();
rootLogger.setLevel(Level.OFF);
final ConsoleAppender ca = (ConsoleAppender) rootLogger.getAppender("stdout");
ca.setLayout(new PatternLayout("%-5p - %m%n"));
// Turn the logger used by the demo back on.
log.setLevel(Level.INFO);
Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR);
}
use of org.apache.log4j.PatternLayout in project incubator-rya by apache.
the class ProspectorExample method setupLogging.
private static void setupLogging() {
// Turn off all the loggers and customize how they write to the console.
final Logger rootLogger = LogManager.getRootLogger();
rootLogger.setLevel(Level.OFF);
final ConsoleAppender ca = (ConsoleAppender) rootLogger.getAppender("stdout");
ca.setLayout(new PatternLayout("%-5p - %m%n"));
// Turn the logger used by the demo back on.
log.setLevel(Level.INFO);
}
Aggregations