use of java.util.logging.Filter 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.Filter in project j2objc by google.
the class HandlerTest method testGetSetFilter_Normal.
/*
* Test getErrorManager with insufficient privilege.
*
public void testGetErrorManager_InsufficientPrivilege() throws Exception {
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
h.getErrorManager();
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setErrorManager with insufficient privilege.
*
public void testSetErrorManager_InsufficientPrivilege() throws Exception {
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
// set null
try {
h.setErrorManager(null);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
// set a normal value
System.setSecurityManager(new MockSecurityManager());
try {
h.setErrorManager(new ErrorManager());
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
*/
/*
* Test getFilter & setFilter methods with non-null value.
*/
public void testGetSetFilter_Normal() throws Exception {
MockHandler h = new MockHandler();
Filter f = new MockFilter();
h.setFilter(f);
assertSame(f, h.getFilter());
}
use of java.util.logging.Filter in project j2objc by google.
the class LoggerTest method testSetFilter_AnonyLoggerSufficientPrivilege.
/*
* Test setFilter with normal value for a named logger, having insufficient
* privilege.
*
public void testGetSetFilter_NamedLoggerInsufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetFilter_NamedLoggerInsufficientPrivilege");
Filter f = new MockFilter();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setFilter(f);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setFilter for an anonymous logger with sufficient privilege.
*/
public void testSetFilter_AnonyLoggerSufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
Filter f = new MockFilter();
assertNull(log.getFilter());
log.setFilter(f);
assertSame(f, log.getFilter());
}
use of java.util.logging.Filter in project j2objc by google.
the class MemoryHandlerTest method testClose.
/*
public void testSecurity() {
SecurityManager currentManager = System.getSecurityManager();
System.setSecurityManager(securityManager);
try {
try {
handler.close();
fail("should throw security exception");
} catch (SecurityException e) {
}
try {
handler.setPushLevel(Level.CONFIG);
fail("should throw security exception");
} catch (SecurityException e) {
}
handler.flush();
handler.push();
handler.getPushLevel();
handler.isLoggable(new LogRecord(Level.ALL, "message"));
handler.publish(new LogRecord(Level.ALL, "message"));
} finally {
System.setSecurityManager(currentManager);
}
}
*/
public void testClose() {
Filter filter = handler.getFilter();
Formatter formatter = handler.getFormatter();
writer.getBuffer().setLength(0);
handler.close();
assertEquals(writer.toString(), "close");
assertEquals(handler.getFilter(), filter);
assertEquals(handler.getFormatter(), formatter);
assertNull(handler.getEncoding());
assertNotNull(handler.getErrorManager());
assertEquals(handler.getLevel(), Level.OFF);
assertEquals(handler.getPushLevel(), Level.WARNING);
assertFalse(handler.isLoggable(new LogRecord(Level.SEVERE, "test")));
}
use of java.util.logging.Filter in project ACS by ACS-Community.
the class AcsLogger method configureLogging.
/**
* Callback method, configures this logger from the data in logConfig.
* @see alma.acs.logging.config.LogConfigSubscriber#configureLogging(alma.acs.logging.config.LogConfig)
*/
public void configureLogging(LogConfig newLogConfig) {
if (newLogConfig == null) {
throw new IllegalArgumentException("newLogConfig must not be null");
}
logConfig = newLogConfig;
try {
UnnamedLogger config = logConfig.getNamedLoggerConfig(getLoggerName());
if (DEBUG) {
System.out.println("*** AcsLogger#configureLogging: name=" + getLoggerName() + " minLevel=" + config.getMinLogLevel() + " minLevelLocal=" + config.getMinLogLevelLocal());
}
configureLevels(config);
} catch (Exception e) {
log(Level.INFO, "Failed to configure logger.", e);
}
// forward log level to optional JacORB filter
// Perhaps this dependency is too dirty, then we need a more general
// filter registration mechanism parallel to what the JDK foresees.
Filter logFilter = getFilter();
if (logFilter != null && logFilter instanceof JacORBFilter) {
((JacORBFilter) logFilter).setLogLevel(getLevel());
}
}
Aggregations