use of java.util.logging.ConsoleHandler in project camel by apache.
the class ManagedSEDeployableContainer method configureLogging.
private void configureLogging(ManagedSEContainerConfiguration configuration) {
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(configuration.getLogLevel());
LOGGER.setUseParentHandlers(false);
LOGGER.addHandler(consoleHandler);
LOGGER.setLevel(configuration.getLogLevel());
}
use of java.util.logging.ConsoleHandler in project checkstyle by checkstyle.
the class Main method runCli.
/**
* Do execution of CheckStyle based on Command line options.
* @param commandLine command line object
* @param filesToProcess List of files to process found from the command line.
* @return number of violations
* @throws IOException if a file could not be read.
* @throws CheckstyleException if something happens processing the files.
*/
private static int runCli(CommandLine commandLine, List<File> filesToProcess) throws IOException, CheckstyleException {
int result = 0;
// create config helper object
final CliOptions config = convertCliToPojo(commandLine, filesToProcess);
if (commandLine.hasOption(OPTION_T_NAME)) {
// print AST
final File file = config.files.get(0);
final String stringAst = AstTreeStringPrinter.printFileAst(file, false);
System.out.print(stringAst);
} else if (commandLine.hasOption(OPTION_CAPITAL_T_NAME)) {
final File file = config.files.get(0);
final String stringAst = AstTreeStringPrinter.printFileAst(file, true);
System.out.print(stringAst);
} else if (commandLine.hasOption(OPTION_J_NAME)) {
final File file = config.files.get(0);
final String stringAst = DetailNodeTreeStringPrinter.printFileAst(file);
System.out.print(stringAst);
} else if (commandLine.hasOption(OPTION_CAPITAL_J_NAME)) {
final File file = config.files.get(0);
final String stringAst = AstTreeStringPrinter.printJavaAndJavadocTree(file);
System.out.print(stringAst);
} else {
if (commandLine.hasOption(OPTION_D_NAME)) {
final Logger parentLogger = Logger.getLogger(Main.class.getName()).getParent();
final ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINEST);
handler.setFilter(new Filter() {
private final String packageName = Main.class.getPackage().getName();
@Override
public boolean isLoggable(LogRecord record) {
return record.getLoggerName().startsWith(packageName);
}
});
parentLogger.addHandler(handler);
parentLogger.setLevel(Level.FINEST);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Checkstyle debug logging enabled");
LOG.debug("Running Checkstyle with version: " + Main.class.getPackage().getImplementationVersion());
}
// run Checker
result = runCheckstyle(config);
}
return result;
}
use of java.util.logging.ConsoleHandler in project cogtool by cogtool.
the class CogTool method enableLogging.
public static void enableLogging(boolean value) {
if (value) {
logger.setLevel(Level.ALL);
for (Handler h : logger.getHandlers()) {
if (h instanceof FileHandler) {
return;
}
}
FileHandler fh = null;
try {
fh = new FileHandler((CogToolPref.LOG_DIRECTORY.getString() + LOG_FILE_PATTERN), LOG_FILE_MAX_SIZE, LOG_FILES_MAX_COUNT, true);
} catch (IOException ex) {
logger.warning("Couldn't create log file: " + ex);
return;
}
fh.setFormatter(new Formatter() {
@Override
public String format(LogRecord r) {
long ms = r.getMillis();
return String.format("%tF %tT.%tL\t%s\n", ms, ms, ms, r.getMessage());
}
});
logger.addHandler(fh);
} else {
logger.setLevel(DEFAULT_LOG_LEVEL);
for (Handler h : logger.getHandlers()) {
if (!(h instanceof ConsoleHandler)) {
logger.removeHandler(h);
}
}
}
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testPublish_AfterResetSystemErr.
/*
* Test publish(), after system err is reset.
*/
public void testPublish_AfterResetSystemErr() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
h.setFilter(new MockFilter());
System.setErr(new PrintStream(new ByteArrayOutputStream()));
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testPublish_WithFilter.
/*
* Test publish(), use a filter, having output stream, normal log record.
*/
public void testPublish_WithFilter() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
h.setFilter(new MockFilter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
h.setLevel(Level.WARNING);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertTrue(CallVerificationStack.getInstance().empty());
assertEquals("", this.errSubstituteStream.toString());
h.setLevel(Level.CONFIG);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
assertTrue(CallVerificationStack.getInstance().empty());
}
Aggregations